private static string GetFileShortcutIcon(string fileFullName) { try { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(fileFullName); string targetFileFullName = shortcut.TargetPath; string ext = Path.GetExtension(targetFileFullName).ToLower(); string copyPath = appDataFolderPath + fileIconPath + ext + shortcutMark + IconFormat; if (System.IO.File.Exists(copyPath)) { } else { Icon icon = Icon.ExtractAssociatedIcon(fileFullName); Bitmap bitmap = icon.ToBitmap(); MemoryStream strm = new MemoryStream(); bitmap.Save(strm, System.Drawing.Imaging.ImageFormat.Png); bitmap.Save(copyPath); } return(copyPath); } catch (Exception) { return(String.Empty); } }
public static int GetFileType(string fileFullName) { ElementAssociationType eat = ElementAssociationType.File; string ext = System.IO.Path.GetExtension(fileFullName).ToLower(); switch (ext) { case ".lnk": try { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(fileFullName); string targetPath = shortcut.TargetPath; if (Directory.Exists(targetPath)) { eat = ElementAssociationType.FolderShortcut; } else { eat = ElementAssociationType.FileShortcut; } } catch (Exception) { eat = ElementAssociationType.FileShortcut; } break; default: eat = ElementAssociationType.File; break; } ; return((int)eat); }
/// <summary> /// SendTo Command /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSendTo_Click(object sender, EventArgs e) { string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.SendTo); string link = string.Format(@"{0}\{1}.lnk", path, this.Text); if (!SendToFlag) { IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut SendTo = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(link); SendTo.TargetPath = this.GetType().Assembly.Location; SendTo.Arguments = ""; SendTo.Description = "Windows系统快捷方法创建工具"; SendTo.WorkingDirectory = System.Environment.CurrentDirectory; SendTo.IconLocation = string.Format("{0},0", this.GetType().Assembly.Location); SendTo.Hotkey = "CTRL+S"; SendTo.WindowStyle = 1; SendTo.Save(); Msg("删除\"发送到\"命令完成", MSG_TYPE.ERROR); } else { System.IO.File.Delete(link); Msg("删除\"发送到\"命令完成", MSG_TYPE.GREEN); } GetSendToButtonStatus(); }
/// <summary> /// Create Windows Shorcut /// </summary> /// <param name="SourceFile">A file you want to make shortcut to</param> /// <param name="ShortcutFile">Path and shorcut file name including file extension (.lnk)</param> /// <param name="Description">Shortcut description</param> /// <param name="Arguments">Command line arguments</param> /// <param name="HotKey">Shortcut hot key as a string, for example "Ctrl+F"</param> /// <param name="WorkingDirectory">"Start in" shorcut parameter</param> public static void CreateShortcut(string SourceFile, string arguments, string ShortcutFile) { // Check necessary parameters first: if (String.IsNullOrEmpty(SourceFile)) { throw new ArgumentNullException("SourceFile"); } if (String.IsNullOrEmpty(ShortcutFile)) { throw new ArgumentNullException("ShortcutFile"); } // Create WshShellClass instance: IWshShell3 wshShell = new WshShellClass(); // Create shortcut object: IWshRuntimeLibrary.IWshShortcut shorcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(ShortcutFile); shorcut.Arguments = arguments; // Assign shortcut properties: shorcut.TargetPath = SourceFile; // Save the shortcut: shorcut.Save(); }
private void OnClick(BaseButton obj) { GameFilePathData gameFilePathData = MainData.Instance.Game_filePathData.Find(p => p.directoryInfo.Name == (obj as GameContentButton).GetName()); FileInfo fileInfo = gameFilePathData.fileInfos.Find(p => p.Extension.ToUpper() == ".LNK"); IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(fileInfo.FullName); Application.OpenURL(shortcut.FullName); Debug.Log(shortcut.FullName); int lenth = 0; while (!shortcut.FullName.Substring(shortcut.FullName.Length - 15 - lenth, 1).Contains(@"\")) { lenth++; } // 除去自己"\" lenth--; string ProcessName = shortcut.FullName.Substring(shortcut.FullName.Length - 15 - lenth, lenth); Debug.Log("ProcessName:" + ProcessName); MainData.Instance.isMainWindow = false; KinectManager.Instance.ClearKinectUsers(); TimeTool.Instance.AddDelayed(TimeDownType.NoUnityTimeLineImpact, 2.0f, () => { MainPanel.Instance.audioSource.Pause(); SoftwareSettingsTool.Instance.productName = ProcessName; }); lastUIPanel.Hide(); }
static void Main(string[] args) { pathStringBuilder path = new pathStringBuilder(); //Console.WriteLine(path.BuildFullPath()); //Console.WriteLine(path.BuildFolderName()); Console.WriteLine(path.BuildDesktopShortcutPath()); //Console.ReadKey(); //Comment in the below for production //Directory.CreateDirectory(path.BuildFullPath()); void CreateShortcut(string linkPath, string filename) { // Create shortcut dir if not exists if (!Directory.Exists(linkPath)) { Directory.CreateDirectory(linkPath); } // COM object instance/props IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut sc = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filename); sc.Description = "Shortcut to today's shortcut folder."; //shortcut.IconLocation = @"C:\..."; sc.TargetPath = linkPath;//ADAM:---------------this needs to be the path to the folder // save shortcut to target sc.Save(); } CreateShortcut(path.BuildFullPath(), path.BuildDesktopShortcutPath()); }
public static void CreateLink(string shortcutFullPath, string target) { WshShell wshShell = new WshShell(); IWshRuntimeLibrary.IWshShortcut newShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutFullPath); newShortcut.TargetPath = target; newShortcut.Save(); }
static void Shortcut(String source, String dest, String description = "") { WshShell wsh = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(dest); shortcut.Arguments = "."; shortcut.TargetPath = source; shortcut.Save(); }
public static void place_shortcut_on_desktop() { string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\YourName.lnk"; string shortcutto = System.Reflection.Assembly.GetExecutingAssembly().Location; var wsh = new IWshShell_Class(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(desktopPath) as IWshRuntimeLibrary.IWshShortcut; shortcut.TargetPath = shortcutto; shortcut.WorkingDirectory = Directory.GetParent(shortcutto).FullName; shortcut.Save(); }
protected override void ProcessRecord() { if (_linkPath != null) { try { WriteVerbose(_cmdlet + ": Starting with" + _linkPath + "."); if (System.IO.File.Exists(_linkPath)) { try { if (this.ShouldProcess(_linkPath, "SetShortcut")) { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut lnk = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(_linkPath); // depends on this openening the existing shortcut! string savetarget = lnk.TargetPath; WriteVerbose(_cmdlet + ": Original targetpath " + Statics.StaticClass.DoubleQuoteMe(savetarget)); lnk.TargetPath = "C:\\Windows\\System32\\reg.exe"; lnk.Arguments = "/import " + savetarget + " " + lnk.Arguments; lnk.Save(); output += _cmdlet + ": SUCCESS Shortcut \"" + _linkPath + "\" updated.\n"; needRefresh = true; } else { output += _cmdlet + ": Shortcut \"" + _linkPath + "\" would have been updated.\n"; } } catch (Exception ex) { output += _cmdlet + ": ERROR Editing \"" + _linkPath + "\" " + ex.Message + "\n"; } } else { output += _cmdlet + ": ERROR File \"" + _linkPath + "\" Does not exist.\n"; } } catch (Exception ex) { output += _cmdlet + ": ERROR Editing \"" + _linkPath + "\" " + ex.Message + "\n"; } } else { output += _cmdlet + ": ERROR Missing required parameter.\n"; } WriteObject(output); if (needRefresh) { SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero); } }
private void AddShortcut(string shortCutPath) { shellLib.WshShell shell = new shellLib.WshShell(); string shortcutPath = shortCutPath; shellLib.IWshShortcut shortcut = (shellLib.IWshShortcut)shell.CreateShortcut(shortcutPath); shortcut.Description = "Ярлык для терминала CTC"; //string terminalDir = Environment.GetEnvironmentVariable("TERMINAL_PATH"); shortcut.TargetPath = PathTerminalExecDir + @"\Terminal.exe"; //Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe"; shortcut.Save(); }
public static void changeAllShortcuts() { string[] files = System.IO.Directory.GetFiles(Paths.ShortcutsPath, "*.lnk"); WshShell wshShell = new WshShell(); foreach (string filePath in files) { IWshRuntimeLibrary.IWshShortcut newShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(filePath); newShortcut.TargetPath = Paths.BackgroundApplication; newShortcut.IconLocation = Path.Combine(Paths.ConfigPath, newShortcut.Arguments.Trim(), "GroupIcon.ico"); newShortcut.WorkingDirectory = Path.Combine(Paths.ConfigPath, newShortcut.Arguments.Trim()); newShortcut.Save(); } }
public void CreateIcon() { string dt = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); dt += "\\ScreenSnip.lnk"; string shortcutLocation = dt; WSH.WshShell shell = new WSH.WshShell(); WSH.IWshShortcut shortcut = (WSH.IWshShortcut)shell.CreateShortcut(shortcutLocation); shortcut.Description = "WolfPaw Screen Snipper tool"; shortcut.TargetPath = Properties.Settings.Default.s_Path + "\\WolfPaw ScreenSnip.exe"; shortcut.Save(); }
/// <summary> /// Used to add the program into startup list /// </summary> public static void AddToStartup() { var startupDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\"; WshShell wsh = new WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( startupDir + "\\" + ShortcutFileName) as IWshRuntimeLibrary.IWshShortcut; shortcut.TargetPath = System.Reflection.Assembly.GetEntryAssembly().Location; shortcut.WindowStyle = 1; shortcut.Description = ShortcutFileDescription; shortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(shortcut.TargetPath); shortcut.Save(); }
/// <summary> /// Creates executable shortcut to the mod /// </summary> public void CreateExe() { string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); object shDesktop = (object)"Desktop"; wsh.WshShell shell = new wsh.WshShell(); string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Ucieczka.lnk"; wsh.IWshShortcut shortcut = (wsh.IWshShortcut)shell.CreateShortcut(shortcutAddress); shortcut.Description = "Uruchom modyfikację G2 Ucieczka"; shortcut.TargetPath = window.GothicPath + @"\System\Gothic2.exe"; shortcut.IconLocation = window.GothicPath + @"\System\Ucieczka.ico"; shortcut.Arguments = "-game:Ucieczka.ini"; shortcut.Save(); }
public void CreateShortcutFile(string appPath, string appName, string destinationPath) { WshShell wsh = new WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(destinationPath + "\\Ung Dung Hoc Tu.lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = appPath + appName; // not sure about what this is for shortcut.WindowStyle = 1; shortcut.Description = "Ứng Dụng Học Từ"; shortcut.WorkingDirectory = appPath; shortcut.IconLocation = appPath + "/Resources/appicon.ico"; shortcut.Save(); }
private static void CreateShortcut(string sdvFolder, string name, string logName, int playerIndex) { WshShell wsh = new WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Path.Combine(sdvFolder, $"{name}.lnk")) as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = $" --log-path \"{logName}.txt\" --player-index {playerIndex}"; shortcut.TargetPath = Path.Combine(sdvFolder, "StardewModdingAPI.exe"); shortcut.WindowStyle = 1; shortcut.Description = name; shortcut.WorkingDirectory = sdvFolder; //shortcut.IconLocation = "specify icon location"; shortcut.Save(); }
private void button1_Click(object sender, EventArgs e) { WshShellClass wsh = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\" + textBox1.Text + ".lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = System.IO.Path.GetFullPath(openFileDialog1.FileName); // not sure about what this is for shortcut.WindowStyle = 10; shortcut.Description = "Create customized Run command"; //shortcut.WorkingDirectory = "C:\\TURBOC3\\Turbo C++\\"; //shortcut.IconLocation = "RunCustomizer.ico"; shortcut.Save(); }
static void Main(string[] args) { string sourcePath = Directory.GetCurrentDirectory() + @"\InstallationFiles\"; string targetPath = @"C:\ZipPassword"; string[] files = System.IO.Directory.GetFiles(sourcePath); string fileName = ""; try { if (!System.IO.Directory.Exists(targetPath)) { System.IO.Directory.CreateDirectory(targetPath); foreach (string s in files) { fileName = System.IO.Path.GetFileName(s); System.IO.File.Copy(s, System.IO.Path.Combine(targetPath + @"\", fileName), true); } } if (System.IO.Directory.Exists(targetPath)) { foreach (string s in files) { fileName = System.IO.Path.GetFileName(s); System.IO.File.Copy(s, System.IO.Path.Combine(targetPath + @"\", fileName), true); } } WshShell wsh = new WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\ZipPassword.lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = targetPath + @"\ZipPassword.exe"; shortcut.WindowStyle = 1; shortcut.WorkingDirectory = targetPath; shortcut.IconLocation = targetPath + @"\ico_password.ico"; shortcut.Save(); Console.WriteLine(string.Format(@"Pliki instalacyjne znajdują się na dysku C:\ w lokalizacji {0} ." + Environment.NewLine + @"Skrót do aplikacji został utworzony na pulpicie." + Environment.NewLine + @"Pozdrawiam, Łukasz D.", targetPath)); } catch (Exception ex) { Console.WriteLine(ex.Message); } Thread.Sleep(10000); }
public Link(string linkLocation) { // Save the link location LinkLocation = linkLocation; // The shortcut does not exist if (!LinkExists) { return; } // Read the shortcut sh.IWshShortcut link = (sh.IWshShortcut)(new sh.WshShell()).CreateShortcut(linkLocation); // Get the relevant properties Icon = link.IconLocation; TargetPath = link.TargetPath; TargetArguments = link.Arguments; Description = link.Description; Title = Path.GetFileNameWithoutExtension(link.FullName); TitleLC = Title.ToLower(); TargetWorkingDirectory = link.WorkingDirectory; Hotkey = link.Hotkey; TargetState = (RunIn)link.WindowStyle; // Convert the RunIn to ProcessWindowStyle if (TargetState == RunIn.Normal) { TargetWindowStyle = ProcessWindowStyle.Normal; } else if (TargetState == RunIn.Maximized) { TargetWindowStyle = ProcessWindowStyle.Maximized; } else if (TargetState == RunIn.Minimized) { TargetWindowStyle = ProcessWindowStyle.Minimized; } // NOTE: Experimental // (https://blogs.msdn.microsoft.com/abhinaba/2013/04/02/c-code-for-creating-shortcuts-with-admin-privilege/) using (FileStream fs = new FileStream(linkLocation, FileMode.Open, FileAccess.Read)) { fs.Seek(21, SeekOrigin.Begin); int b = fs.ReadByte(); TargetAsAdmin = (b & 0x22) > 0; } }
private void CreateShotcut(string newPackageName) { string path = Application.StartupPath; WshShellClass wsh = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + newPackageName + ".lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = "\"" + newPackageName + "\""; shortcut.TargetPath = path + "\\CDT.exe"; // not sure about what this is for shortcut.WindowStyle = 1; shortcut.Description = newPackageName; shortcut.WorkingDirectory = path; shortcut.Save(); }
public static void AppShortcutToDesktop() //Creates a shortcut to the desktop. { string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); WshShell wsh = new WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Scoring Report.lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = "C:\\Dynamix\\score_report.html"; shortcut.WindowStyle = 1; shortcut.Description = "Windows Scoring Report"; shortcut.WorkingDirectory = "c:\\Dynamix"; shortcut.IconLocation = "C:\\Dynamix\\dx-128-icon.ico"; shortcut.Save(); }
public void CreateShortcut(string shortcutName, string shortcutPath, string shortcutDescription, string directory, string shortcutArguments) { WshShell wsh = new WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + shortcutName + ".lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = shortcutArguments; shortcut.TargetPath = shortcutPath; // c:\\app\\myftp.exe // not sure about what this is for shortcut.WindowStyle = 1; shortcut.Description = shortcutDescription; // my shortcut description shortcut.WorkingDirectory = directory; // c:\\app // shortcut.IconLocation = "specify icon location"; // specify icon location shortcut.Save(); loadingLog.Text += "Snarvei til " + shortcutName + "\r\n"; }
public static void CreateDesktopLnk(string AppPath) { string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到桌面文件夹 IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(DesktopPath + "\\GBT.lnk"); shortcut.TargetPath = AppPath + "GBT.exe"; shortcut.Arguments = ""; //参数 shortcut.Description = "http://gamelab.1111"; shortcut.WorkingDirectory = System.Environment.CurrentDirectory; //程序所在文件夹,在快捷方式图标点击右键可以看到此属性 shortcut.IconLocation = AppPath + "GBT.exe,0"; //图标 shortcut.Hotkey = ""; //热键 shortcut.WindowStyle = 1; shortcut.Save(); }
/// <summary> /// Create Windows Shorcut /// </summary> /// <param name="SourceFile">A file you want to make shortcut to</param> /// <param name="ShortcutFile">Path and shorcut file name including file extension (.lnk)</param> /// <param name="Description">Shortcut description</param> /// <param name="Arguments">Command line arguments</param> /// <param name="HotKey">Shortcut hot key as a string, for example "Ctrl+F"</param> /// <param name="WorkingDirectory">"Start in" shorcut parameter</param> public static void CreateShortcut(string TargetPath, string ShortcutFile, string Description, string Arguments, string HotKey, string WorkingDirectory, int logo) { // Check necessary parameters first: if (String.IsNullOrEmpty(TargetPath)) { throw new ArgumentNullException("TargetPath"); } if (String.IsNullOrEmpty(ShortcutFile)) { throw new ArgumentNullException("ShortcutFile"); } // Create WshShellClass instance: var wshShell = new WshShell(); // Create shortcut object: IWshRuntimeLibrary.IWshShortcut shorcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(ShortcutFile); if (logo == 1) { shorcut.IconLocation = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Iwit Systems\\iwit sync\\dossier-iwit.ico"; } else if (logo == 2) { shorcut.IconLocation = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Iwit Systems\\iwit sync\\dossier-iwit.ico"; } // Assign shortcut properties: shorcut.TargetPath = TargetPath; shorcut.Description = Description; if (!String.IsNullOrEmpty(Arguments)) { shorcut.Arguments = Arguments; } if (!String.IsNullOrEmpty(HotKey)) { shorcut.Hotkey = HotKey; } if (!String.IsNullOrEmpty(WorkingDirectory)) { shorcut.WorkingDirectory = WorkingDirectory; } // Save the shortcut: shorcut.Save(); }
public void CreateConfig(Image groupImage) { string path = @"config\" + this.Name; string filePath = path + @"\" + this.Name + "Group.exe"; // // Directory and .exe // System.IO.Directory.CreateDirectory(@"Shortcuts\"); System.IO.Directory.CreateDirectory(@path); System.IO.File.Copy(@"config\config.exe", @filePath); // // XML config // System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(Category)); using (FileStream file = System.IO.File.Create(@path + @"\ObjectData.xml")) writer.Serialize(file, this); // // Create .ico // Image img = ImageFunctions.ResizeImage(groupImage, 1024, 1024); // Resize img if too big img.Save(path + @"\GroupImage.png"); using (FileStream fs = new FileStream(path + @"\GroupIcon.ico", FileMode.Create)) ImageFunctions.IconFromImage(img).Save(fs); // saving as icon // // Create .lnk shortcut // var wsh = new IWshShell_Class(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( path + "\\" + this.Name + ".lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = Path.GetFullPath(@filePath); shortcut.WindowStyle = 1; shortcut.Description = path + " shortcut"; shortcut.WorkingDirectory = Path.GetFullPath(@path); shortcut.IconLocation = Path.GetFullPath(path + @"\GroupIcon.ico"); shortcut.Save(); System.IO.File.Move(@path + "\\" + this.Name + ".lnk", Path.GetFullPath(@"Shortcuts\" + this.Name + ".lnk")); // moving .lnk to correct directory }
private static void updateDeskTopShortCutDescription(string shortcutName) { WshShell wsh = new WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + shortcutName + ".lnk") as IWshRuntimeLibrary.IWshShortcut; //shortcut.Arguments = ""; //shortcut.TargetPath = "c:\\app\\myftp.exe"; string curVersion = ApplicationDeployment.IsNetworkDeployed ? ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString() // retourne la bonne version en exécution : Assembly.GetExecutingAssembly().GetName().Version.ToString(); //le 2e retourne : 1.0.0.0 shortcut.Description = "XLApp, Version " + DateTime.Now.Year % 100 + "." + curVersion; //shortcut.WorkingDirectory = "c:\\app"; //shortcut.IconLocation = "specify icon location"; shortcut.Save(); }
private static void Delete(DirectoryInfo di, string xmlName) { string fileFullPath = di.FullName + Path.DirectorySeparatorChar + xmlName; if (System.IO.File.Exists(fileFullPath)) { try { FileSystem.DeleteFile(fileFullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } catch (Exception ex) { Console.WriteLine("The following file cannot be deleted. "); Console.WriteLine(fileFullPath); Console.WriteLine("Error: " + ex.Message); Console.WriteLine(); } foreach (DirectoryInfo sub_di in di.GetDirectories()) { Delete(sub_di, xmlName); } foreach (FileInfo fi in di.GetFiles()) { if (fi.FullName.EndsWith(".lnk")) { try { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(fi.FullName); string folderPath = shortcut.TargetPath; if (Directory.Exists(folderPath)) { Delete(new DirectoryInfo(folderPath), xmlName); } } catch (Exception ex) { } } } } }
private void CreateShortcut(string linkname) { if (!Directory.Exists(installPath + "\\Resources\\shortcuts")) { System.IO.Directory.CreateDirectory(installPath + "\\Resources\\shortcuts"); } WshShell wsh = new WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( installPath + "\\Resources\\shortcuts" + "\\" + EditTitle.Text + ".lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = linkname; shortcut.WindowStyle = 1; shortcut.Description = "Shortcut to " + EditTitle.Text; shortcut.WorkingDirectory = "C:\\App"; shortcut.IconLocation = linkname; shortcut.Save(); }
/// <summary> /// Create Shortcut and copy it to desktop /// </summary> public static void CreateShortcut() { var exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; var iconPath = $@"{System.IO.Path.GetDirectoryName(exePath)}\resources\forceSync.ico"; var deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); var linkPath = $@"{deskDir}\OnedriveForceSync.lnk"; WshShell wsh = new WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(linkPath) as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = "--nogui"; shortcut.TargetPath = exePath; // not sure about what this is for shortcut.WindowStyle = 1; shortcut.Description = "Force Sync"; shortcut.WorkingDirectory = System.IO.Path.GetFullPath(exePath); shortcut.IconLocation = iconPath; shortcut.Save(); }