当期环境:Win11家庭版
注:批处理文件编码方式需设置为ANSI
启动服务:
@echo off >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" if '%errorlevel%' NEQ '0' ( goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" exit /B :gotAdmin if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) echo 关闭服务 net stop "CloudFilmLaunchService" echo 开启服务 net start "CloudFilmLaunchService" pause
方式二:
@echo off @title Installing windows services path %SystemRoot%\Microsoft.NET\Framework\v4.0.30319 echo============================================================== echo= echo Windows Service program installation echo= echo============================================================== @echo off InstallUtil.exe CloudFilmLaunchService.exe pause
卸载服务:
@echo off @title Windows service uninstall path %SystemRoot%\Microsoft.NET\Framework\v4.0.30319 echo============================================================== echo= echo Windows service uninstall echo= echo============================================================== @echo off InstallUtil.exe /u CloudFilmLaunchService.exe pause
安装XXWindowsService,[SC] OpenService 失败
服务命令无法启动,参考:https://blog.csdn.net/qq_39569480/article/details/124150871 解决问题
1.使用管理员身份运行VS 重新生成服务文件
2.修改注册表配置,重启电脑,配置如下:
打开cmd,输入regedit,进入注册表==》HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA 的值改为0
计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA 的值改为0
标签:批处理,exe,temp%,C#,getadmin,echo,vbs,Windows From: https://www.cnblogs.com/YYkun/p/17485811.html