且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何查找单击的快捷方式(.lnk)路径?

更新时间:2023-01-31 12:09:37

这不是一个好的解决方案。您应该为每个快捷方式添加不同的命令行参数。喜欢-desktop,-program -startup。



您可以通过命令行参数检测应用程序是否启动了哪种快捷方式。


嗨BreakPoint,



感谢您的解决方案,我得到了它并添加了如下代码:



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; // 参数需要在这里传递
shortcut.IconLocation = appStartPath + \\logo.ico;
shortcut.Save();







这次改变之后我能够获得价值来自以下功能,



  public   static   bool  StartupFlag =  false ; 
受保护 覆盖 void OnStartup (StartupEventArgs e)
{

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

}


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,

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,

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.


Hi BreakPoint,

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

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,

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;
           }

       }