Search code examples
batch-filecmdinno-setup

Create shortcut to cmd to execute a batch file in Inno Setup


I use a batch script start.bat to run my program. I create a shortcut for this purposes as shown below:

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\start.bat"; \
    IconFilename: "{app}\{#MyAppIcoName}"; Tasks: desktopicon
Name: "{userdesktop}\{#MyAppName}"; Filename: "{app}\start.bat"; \
    IconFilename: "{app}\{#MyAppIcoName}"; Tasks: desktopicon

In order for the user to be allowed to drag the shortcut to a batch file to the taskbar (Windows 10) I have to modify the shortcut path from E:\Soft\MyProgram\start.bat to cmd /c E:\Soft\MyProgram\start.bat. But I can't just change the path to Filename: "cmd /c {app}\start.bat"; it doesn't work. Any ideas?


Solution

  • cmd /c E:\Soft\MyProgram\start.bat
    

    The above command executes cmd.exe program with /c E:\Soft\MyProgram\start.bat as its parameters.

    In Inno Setup Icons section, you specify the parameters using Parameters parameter:

    [Icons]
    Name: "{userdesktop}\{#MyAppName}"; Filename: "cmd"; \
        Parameters: "/c E:\Soft\MyProgram\start.bat"; \
        IconFilename: "{app}\{#MyAppIcoName}"; Tasks: desktopicon
    
    • Though instead of hard-coding cmd, you should use {cmd} constant.
    • Similarly, I assume that instead of E:\Soft\MyProgram, you should use {app}.
    • Wrap the path to double quotes, in case it contains spaces.
    • In some cases, the batch file might be designed to only work when executed from its directory. For that add WorkingDir parameter.
    [Icons]
    Name: "{userdesktop}\{#MyAppName}"; Filename: "{cmd}"; \
        Parameters: "/c ""{app}\start.bat"""; WorkingDir: "{app}" \
        IconFilename: "{app}\{#MyAppIcoName}"; Tasks: desktopicon