From df6a1eaeab73894552141a19fd5705b2b140bb66 Mon Sep 17 00:00:00 2001 From: Winston Liu Date: Thu, 7 Mar 2024 22:21:24 -0800 Subject: [PATCH] Properly quote sc.exe create's binPath argument 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. --- GVFS/GVFS.Installers/Setup.iss | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GVFS/GVFS.Installers/Setup.iss b/GVFS/GVFS.Installers/Setup.iss index ca93ac914..109f4f45b 100644 --- a/GVFS/GVFS.Installers/Setup.iss +++ b/GVFS/GVFS.Installers/Setup.iss @@ -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