Click here to Skip to main content
15,938,446 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to know user clicked the shortcut Whether from Desktop shortcut or all programs -> start up shortcut?

I am using the following code to create shortcuts,

C#
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
 IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(strStartup + "\\filename.lnk");
                shortcut.TargetPath = Application.ResourceAssembly.Location;
                shortcut.WindowStyle = 1;
                shortcut.IconLocation = appStartPath + "\\logo.ico";
                shortcut.Save();


I am unable to get the shortcut path or property of shortcuts where it as created.

Whatever I have googled I am getting the application (.exe) file path only not getting shortcut (.lnk) path.

Please help me out this issue.
Thanks,
Posted
Comments
Status BreakPoint 7-Aug-13 5:46am    
I guess this is impossible. Why do you need to know?
Member 7686563 7-Aug-13 7:20am    
Actually I have created shortcuts in three places such as Desktop,Programs,Start up.
Here I need to know the application starts from which shortcut because If application starts from Start up then should show only tray icon and not to show the application window. This is situation.

This is not good solution. You should put different command line argument for each shortcuts. like -desktop, -program -startup.

You can detect whether application is launched which shortcut by command line arguments.
 
Share this answer
 
Hi BreakPoint,

Thanks for your solution, I got it and added code as follows :

C#
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
 IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(strStartup + "\\filename.lnk");
                shortcut.TargetPath = Application.ResourceAssembly.Location;
                shortcut.WindowStyle = 1;
                shortcut.Arguments = "startup"; //arguments needs to be passed here
                shortcut.IconLocation = appStartPath + "\\logo.ico";
                shortcut.Save();



After this change I can able to get value from following function,

C#
public static bool StartupFlag=false;
protected override void OnStartup(StartupEventArgs e)
       {

           if (e.Args.Length == 1 && e.Args[0] == "startup")
           {
               StartupFlag = true;
           }
           else
           {
               StartupFlag = false;
           }

       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900