static void CreateShortcut(string FullFolderPath) { string FolderName = Path.GetFileNameWithoutExtension(FullFolderPath); string FolderDir = Path.GetDirectoryName(FullFolderPath); string FolderRoot = Path.GetPathRoot(FullFolderPath); string lnkPath = Path.Combine(FolderDir, FolderName) + ".lnk"; File.WriteAllBytes(lnkPath, new byte[] { }); Shell32.Shell shl = new Shell32.ShellClass(); Shell32.Folder dir = shl.NameSpace(FolderDir); Shell32.FolderItem itm = dir.Items().Item(FolderName + ".lnk"); Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink; lnk.Path = FolderRoot + "\\execute.bat"; lnk.Description = FolderName; lnk.Arguments = "\"" + FullFolderPath + "\""; lnk.WorkingDirectory = FolderDir; SHFILEINFO shinfo = new SHFILEINFO(); Win32.SHGetFileInfo(FullFolderPath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), (int)0x1000); lnk.SetIconLocation(shinfo.szDisplayName, shinfo.iIcon); lnk.Save(lnkPath); }
static void createLink(string path, string name) {//c:\windows\system32\shell32.dll Shell32.Shell shl = new Shell32.Shell(); StreamWriter sw = new StreamWriter(path + "\\" + name + ".lnk", false); sw.Close(); Shell32.Folder dir = shl.NameSpace(path); Shell32.FolderItem itm = dir.Items().Item(name + ".lnk"); Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink; lnk.Path = Application.ExecutablePath; lnk.Description = "pżyłożeńe"; lnk.Arguments = ""; lnk.WorkingDirectory = Application.ExecutablePath.ToString().Substring(0, Application.ExecutablePath.ToString().LastIndexOf('\\')); lnk.SetIconLocation(Application.ExecutablePath, 0); lnk.Save(); }
public static void CreateShortcut(string gameExePath, string shortcutName, string shortcutPath, string targetFileLocation) { string shortcutLocation = Path.Combine(shortcutPath, shortcutName); // Create empty .lnk file File.WriteAllBytes(shortcutName, new byte[0]); // Create a ShellLinkObject that references the .lnk file Shell32.Shell shl = new Shell32.Shell(); Shell32.Folder dir = shl.NameSpace(Path.GetDirectoryName(shortcutLocation)); Shell32.FolderItem itm = dir.Items().Item(shortcutName); Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink; // Set the .lnk file properties lnk.Path = targetFileLocation; lnk.Arguments = "-c \"" + Path.GetFileNameWithoutExtension(gameExePath) + ".ini\""; lnk.WorkingDirectory = Path.GetDirectoryName(targetFileLocation); lnk.SetIconLocation(gameExePath.Replace('\\', '/'), 0); lnk.Save(shortcutName); }
private void CreateShortcut(object sender, RoutedEventArgs e) { var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var lnkName = "FL Studio (skinned)"; string lnkPath = System.IO.Path.Combine(desktopFolder, lnkName) + ".lnk"; System.IO.File.WriteAllBytes(lnkPath, new byte[] { }); Shell32.Shell shl = new Shell32.ShellClass(); Shell32.Folder dir = shl.NameSpace(desktopFolder); Shell32.FolderItem itm = dir.Items().Item(lnkName + ".lnk"); Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink; lnk.Path = System.Reflection.Assembly.GetExecutingAssembly().Location; lnk.Arguments = "-nogui"; lnk.WorkingDirectory = System.IO.Path.GetDirectoryName(lnk.Path); lnk.SetIconLocation(string.Format(@"{0}\FL64.exe", Config.current.flStudioPath), 0); lnk.Save(lnkPath); }