Skip to content

Commit

Permalink
Properly quote sc.exe create's binPath argument
Browse files Browse the repository at this point in the history
If the binPath isn't quoted, sc.exe will first look for a file at C:\Program.
Starting that will yield CreateProcess error 193 (aka invalid Win32 program).

By properly quoting the binPath, we guarantee that the correct file will be loaded.
  • Loading branch information
winstliu committed Mar 8, 2024
1 parent 3790eb0 commit df6a1ea
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion GVFS/GVFS.Installers/Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ begin
WizardForm.StatusLabel.Caption := 'Installing GVFS.Service.';
WizardForm.ProgressGauge.Style := npbstMarquee;
// Spaces after the equal signs are REQUIRED.
// https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/sc-create#remarks
try
if Exec(ExpandConstant('{sys}\SC.EXE'), ExpandConstant('create GVFS.Service binPath="{app}\GVFS.Service.exe" start=auto'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode = 0) then
// We must add additional quotes to the binPath to ensure that they survive argument parsing.
// Without quotes, sc.exe will try to start a file located at C:\Program if it exists.
if Exec(ExpandConstant('{sys}\SC.EXE'), ExpandConstant('create GVFS.Service binPath= "\"{app}\GVFS.Service.exe\"" start= auto'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode = 0) then
begin
if Exec(ExpandConstant('{sys}\SC.EXE'), 'failure GVFS.Service reset= 30 actions= restart/10/restart/5000//1', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
Expand Down

0 comments on commit df6a1ea

Please sign in to comment.