使用引号中的 binpath 在 NSIS 中创建服务

create service in NSIS with binpath in quotes

直到今天,我一直在使用.nsi 文件中的以下代码来创建服务:

nsExec::Exec 'SC CREATE "MyService" binpath= "$APPDATA\My App Folder\service\SService.exe" start="auto"'
nsExec::Exec 'sc description "MyService" "Starts The Service"'

效果很好,但截至今天,创建的服务无法启动,错误为:error 193 0xc1,或者换句话说,服务路径不正确。我打开注册表编辑器 Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService 并将 C:\ProgramData\My App Folder\service\SService.exe 更改为 "C:\ProgramData\My App Folder\service\SService.exe"(添加引号),它又开始工作了。

问题是,如何创建一个包含 "" 的 binpath?我试过了

 nsExec::Exec 'SC CREATE "MyService" binpath= "$\"$APPDATA\My App Folder\service\SService.exe$\"" 

但从未创建服务。在 NSIS 中创建带有 "" 的二进制路径的正确语法是什么?如果您有任何想法,为什么 windows 突然决定在没有 "" 的情况下不接受我的路径,请也分享这些知识。

这与 NSIS 无关,您只是没有使用 sc.exe 的正确语法。 sc.exe 可能使用 MSVC rules for command line parsing 这意味着您必须使用 \".

nsExec::Exec '"$sysdir\sc.exe" CREATE "MyService" binpath= "\"$APPDATA\My App Folder\service\SService.exe\"" start= auto'
Pop [=10=] ; Exit code