2013-02-06 82 views
0

我基本上想检查当前程序是否已经链接到Windows启动文件夹,即使该文件有另一个名称或从另一个目录运行。这是可能的,也许通过检查程序的名字?检查启动文件夹是否已经包含程序

PS:我用这个代码,以我的程序链接到启动文件夹:

using (ShellLink shortcut = new ShellLink()) { 
    shortcut.Target = Application.ExecutablePath; 
    shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath); 
    shortcut.Description = "My Shorcut Name Here"; 
    shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; 
    shortcut.Save(Environment.GetFolderPath(Environment.SpecialFolder.Startup)); 
} 

感谢。

回答

0

您需要扫描启动的开始菜单文件夹,并为每个快捷方式比较目标路径与程序的路径。

WshShell shell = new WshShell(); 
var link = (IWshShortcut)shell.CreateShortcut(linkPathName); //Link the interface to our shortcut 
var target = link.TargetPath; 
//compare to your program's path... 
+0

难道应用程序可能从任何位置运行,就像我上面写的那样?所以它不应该检查路径,它应该检查程序的名称/ ID(如果类似的东西存在)。 – Marius

+0

然后你必须在运行时获得程序的路径,这个http://msdn.microsoft.com/en-us/library/system.windows.forms.application.startuppath.aspx – CharlesB

+0

感谢您的网址! – Marius

0

试着写一个木马? = D

简单的解决方案:枚举启动文件夹中的所有快捷方式(lnk文件),全部打开它们并看到(我假设您使用的是this技术)。

+0

我不写一个木马;)。查看我在CharlesB的帖子中的评论。 – Marius

相关问题