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 ?

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;

Leave a Reply