Search code examples
nsis

create service in NSIS with binpath in quotes


Up to today, I was using the follwing code in .nsi file to create a service:

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

It worked great, but as of today the service created cannot be started with the error: error 193 0xc1, or in other words, the path to service is incorrect. I opened registry Editor Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService and changed C:\ProgramData\My App Folder\service\SService.exe to "C:\ProgramData\My App Folder\service\SService.exe" (added quotes) and it started working again.

The question is, how can I create a binpath with "" around it? I tried

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

but the service is never created. What is the correct syntax to create a binpath with "" around it in NSIS? If you have any idea, why windows suddenly decided that it wont accept my path without the "", please share that knowledge as well.


Solution

  • This has nothing to do with NSIS, you are simply not using the correct syntax for sc.exe. sc.exe probably uses the MSVC rules for command line parsing which means you must use \".

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