#原理很简单,在注册表中加一个值就行 这是最简单的一种实现方案,但是执行的时候要使用管理员权限
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" /v "arpbd" /t REG_SZ /d "你想要启动程序的绝对路径"
注册服务bat
@echo.服务启动......
@echo off
@sc create test3 binPath= "E:\lcgx\server\bin\run.bat"
@net start test3
@sc config test3 start= AUTO
@echo off
@echo.启动完毕!
@pause
开机自启的例子,不是很好用,做一个记录
@echo off
echo REGEDIT4>x.reg
echo.
echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\run]>>x.reg
echo "bat"="启动程序的路径">>x.reg
regedit /s x.reg &del x.reg
pause
#复制并且替换已经存在的文件 xcopy
xcopy 文件路径 绝对文件路径 /e /y
#请求管理员权限
@echo off
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B