Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why isn't shortcut made programatically working properly?

I use this code to make a shortcut to my app while installing it :

private void CreateShortcut()
{
    object shDesktop = (object)"Desktop";
    WshShell shell = new WshShell();
    string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Baseet.lnk";
    IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
    shortcut.Description = "Baseet Program";
    shortcut.Hotkey = "Ctrl+Shift+N";
    shortcut.TargetPath = Environment.CurrentDirectory + @"\Start_Baseet.exe";
    shortcut.Save();
}

The original app’s job is to open an access database. When it can’t find the database an error message is shown to the user to tell them that the database is missing and it’s working just fine .

The problem is that the shortcut made by previously mentioned code is showing the error message "the database is missing" when at the same time the original app of that shortcut is working just fine. How is that possible ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Long story short : I made a shortcut to a perfectly working app, but the shortcut is showing a customized error message I put in my code, which can’t be shown because the requirements are all there.

>Solution :

try to set the WorkingDirectory-Property:

shortcut.WorkingDirectory = Environment.CurrentDirectory;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading