Home > Blockchain >  Passing argument with sc create command in Inno Setup
Passing argument with sc create command in Inno Setup

Time:01-11

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.

CodePudding user response:

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:

cs create ByTestService start= auto binPath="\"C:\Program Files (x86)\Accenture\Vytelle.DataService.Worker.exe\" ThisisParameter"
  • Related