wpf lnk

Posted on 2017-05-26 15:36  KA卡尔特人头狼  阅读(134)  评论(0编辑  收藏  举报

Add Reference——>COM——>Windows Script Host Object Model;

using IWshRuntimeLibrary;

 

private void CheckStartup()
{
string sStartup = Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
//Get All Startup Item
List<string> files = new List<string>(Directory.GetFiles(sStartup,"*.lnk"));
foreach(var ink in files)
{
if(System.IO.File.Exists(ink))
{
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(ink);
string sDesPath = shortcut.TargetPath;
string sWorkingPath = shortcut.WorkingDirectory;

string sTail = sDesPath.Substring(sDesPath.Length-8,8);
if(sTail.Equals("demo.exe"))
{
var iPathLen = sDesPath.Length;
if(iPathLen>25)
{
string sHead = sDesPath.Substring(3, 13);
if (!sHead.Equals("Program Files"))
{
Directory.Delete(sWorkingPath, true);
System.IO.File.Delete(ink);
}
}
else
{
Directory.Delete(sWorkingPath, true);
System.IO.File.Delete(ink);
}
}
}
}
}