How to spec a shortcut using VS Setup Project to open a Command Prompt at the Application Folder

61 views Asked by At

I have created a Console project (called BasList) in VS Community 2022 and added a Setup Project to the solution. I want end users to be able to click BasList in the Program Menu, or a shortcut on the desktop, to open the Command Prompt at the application folder, ready for them to type BasList ... and run the program.

It is easy to do manually -- just create a shortcut with cmd.exe as the target, and the application folder in the Start In field. However, the latter needs to be set by the installer, as the application could be installed anywhere, not necessarily to the default location.

Surely I cannot be the only person on the planet who has created a Console application and wants users to be able to start it easily?

STEPS TRIED SO FAR In the Setup project I right-clicked the setup project in Solution Explorer and pointed to View > File System. In the file system I selected User's Desktop and on the right side right-clicked and pointed to Create New Shortcut. In the dialog box that is displayed, I cannot type in the Source Path field, but if I select User's Desktop in the Look In drop-down, I can click Add File, add cmd.exe and click OK. This adds both cmd.exe and a shortcut to it in that folder. I modify the properties of the shortcut to put Application Folder in the WorkingFolder field.

When I build it, I get WARNING: File 'cmd.exe' should not be installed into a User's Profile folder because it may not be available to all users. Have also seen warnings about it being a system file.

This procedure works, in that I get a shortcut on the desktop that does what I want. But cmd.exe is copied there too, and if I delete it manually, double-clicking the shortcut gives a brief message about Installer, there's a User Account dialog from C:\Windows\Installer\xxxx.msi (some numbers instead of xxxx) and finally says Warning 1909.Could not create Shortcut Baslist.lnk. After I dismiss that, it opens the Command Prompt correctly, but has reinstated cmd.exe on the desktop.

If, however, I delete cmd.exe from the Setup project, leaving just the shortcut, which says 'cmd.exe' in the Target field, it will not build: ERROR: Invalid or unspecified target for shortcut 'BasList'.

I should be able to spec a shortcut and type into the Target and WorkingFolder fields, but they are both greyed out, leaving only the little ellipsis icons ('...') as a way to change them.

Workarounds I have tried

  • Bing Chat suggested adding commands to the target to CD to the correct folder. Apart from the fact it won't let me modify the Target field, it would hardcode the folder.
  • Created a shortcut manually, copied it into the main application folder (BasList), set it as Content and Copy Always. In Setup, right-click on the right-hand side, point to Add > Project Output... and select Content Files. This works, but again the WorkingFolder / Start In folder (Isn't Microsoft wonderfully consistent?) is hardcoded, and if left blank starts in System32 or the desktop.
1

There are 1 answers

0
Andrew Rowland On

I have downloaded Inno Setup (http://www.jrsoftware.org/). Doing this is a piece of cake -- as it should be in WIx, and I believe used to be possible when you could just type [Application Folder] instead of being hand-held to the degree you are now.

In the Inno script's [Icons] section, do this:

[Icons]
Name: "{autodesktop}\{#MyAppName}"; Filename: "cmd.exe"; Parameters: "/k cd /d ""{app}"""; Tasks: desktopicon
Name: "{group}\{#MyAppName}"; Filename: "cmd.exe"; Parameters: "/k cd /d ""{app}""";