1

I have a Inno Setup file containing code like :

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "My Program"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "https://www.example.com/"
#define MyAppExeName "Vytelle.DataService.Worker.exe"
#define MyAppAssocName MyAppName + " File"
#define MyAppAssocExt ".myp"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{72A0FB9B-516C-472D-886D-4DA0727FD72C}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
ChangesAssociations=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputBaseFilename=mysetup
OutputDir=D:\
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "D:\vytelle.dataservice\Vytelle.DataService\Vytelle.DataService.Worker\bin\Debug\net7.0\publish\win-x64\*"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Registry]
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: ""

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: {sys}\sc.exe; Parameters: "create ByTestService start= auto binPath=""""{app}\{#MyAppExeName}"" ThisisParameter" ; Flags: runhidden




But after installing, getting process code 1639 (wrong arguments error code)

enter image description here

Just want to know how to pass parameter with sc create command as you see in the run script of the give code.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164

1 Answers1

1

You have two problems:

So your commandline won't work even standalone, let alone in Inno Setup.

The correct syntax is:

"create ByTestService start= auto binPath=""\""{app}\{#MyAppExeName}\"" ThisisParameter"""

Note: the backslash in \"" (twice) and the three trailing quotes """ (first two for trailing quote in sc binPath and the third to match the leading quote in Parameters).

This ultimately executes:

sc create ByTestService start= auto binPath="\"C:\Program Files (x86)\Accenture\Vytelle.DataService.Worker.exe\" ThisisParameter"
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Genuinely Thank you for the quick response @Martin. It really works for me. I found an alternate way that you could get the same by registering the value in the imagePath variable in the registry editor of any service like [Registry] --Root: HKA; Subkey: "SYSTEM\CurrentControlSet\Services\ChiService"; ValueType: string; ValueName: "imagePath"; ValueData: "{app}\{#MyAppExeName} {code:GetParams}" – Haris Hussain Jan 10 '23 at 12:45
  • @HarisHussain Aren't you missing quotes around exe path in `ValueData`, in case the path contains quotes (what it does)? – Martin Prikryl Jan 11 '23 at 06:38
  • No @Martin it will return the exact path with my given parameters but I'm using the approach which got from you. And I definitely give a thumbs up for the correct answer but I need 15 reputations to cast a vote that's why only accepting it but will surely do it when I get the reputations. Thanks – Haris Hussain Jan 11 '23 at 11:48