之前用windows的计划任务实现的开机自启动frpc方案,一段时间后莫名其妙地就启动不成功了。也排查不出问题在哪,没办法,只能再找一个方案了。
在网上查到,利用winsw.exe
程序就能实现任意脚本或者程序的服务化。
https://github.com/kohsuke/winsw/releases
winsw.xml
创建一个配置文件winsw.xml
<configuration>
<id>FRPC</id>
<name>FRPC</name>
<description>keep frpc proc for control this computer anytime and anywhere.</description>
<executable>%BASE%\frpc.exe</executable>
<log mode="none"></log>
</configuration>
install.bat
然后再创建一个安装脚本install.bat
,
里面包含了申请提权的代码,
以及设置为开机自启动
@echo off
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :uacfalse
:runas
%~dp0winsw.exe install
net start FRPC
sc config FRPC start=auto
echo 安装成功
pause
goto :eof
:uacfalse
uninstall.bat
接下来再创建一个卸载的脚本uninstall.bat
@echo off
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :uacfalse
:runas
net stop FRPC
%~dp0winsw.exe uninstall
echo 卸载成功
pause
goto :eof
:uacfalse