您不需要使用特殊的庫來創建快捷方式,您可以直接從C#或VB.NET程序中使用Shell32自動化對象。開始使用項目+添加引用,瀏覽選項卡中,選擇C:\ WINDOWS \ SYSTEM32 \ shell32.dll中
然後寫這樣的代碼來創建.lnk文件:
// Creating a link named "test" on the desktop
string lnkDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string lnkName = "test";
// Create an empty .lnk file so we can create an object for it
string lnkPath = System.IO.Path.Combine(lnkDir, lnkName) + ".lnk";
System.IO.File.WriteAllBytes(lnkPath, new byte[] { });
// Initialize a ShellLinkObject for that .lnk file
Shell32.Shell shl = new Shell32.ShellClass();
Shell32.Folder dir = shl.NameSpace(lnkDir);
Shell32.FolderItem itm = dir.Items().Item(lnkName + ".lnk");
Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink;
// We'll just dummy a link to notepad
lnk.Path = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe";
lnk.Description = "Anything goes here";
lnk.Arguments = @"c:\sample.txt";
lnk.WorkingDirectory = @"c:\";
// And dummy an icon (it will the one used by cmd.exe)
lnk.SetIconLocation(Environment.GetFolderPath(Environment.SpecialFolder.System) + "cmd.exe", 1);
// Done, save it
lnk.Save(lnkPath);
使用'IShellLink'和' IPersistFile'來創建快捷方式。很多文章展示瞭如何從.net中做到這一點。例如:http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Creating_and_Modifying_Shortcuts/article.asp –
你們都是如此輕鬆愉快。另一個問題甚至沒有提到64位。我發誓我不知道爲什麼我繼續支持這個網站。 –