/// ******************************************************************* /// <summary> /// ショートカットの作成 /// </summary> /// <param name="srcPath">参照元のファイル</param> /// <param name="dstPath">作成先のディレクトリ</param> /// ******************************************************************* public static void MakeShortcut(string srcPath, string dstPath) { // ショートカットそのもののパス string shortcutPath = dstPath + @"\" + FileUtillity.GetFileName(srcPath) + @".lnk"; // ショートカットのリンク先(起動するプログラムのパス) string targetPath = srcPath; // WshShellを作成 IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); // ショートカットのパスを指定して、WshShortcutを作成 IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath); // ①リンク先 shortcut.TargetPath = targetPath; // ②引数 shortcut.Arguments = "/a /b /c"; // ③作業フォルダ shortcut.WorkingDirectory = Application.StartupPath; // ④実行時の大きさ 1が通常、3が最大化、7が最小化 shortcut.WindowStyle = 1; // ⑤コメント shortcut.Description = "テストのアプリケーション"; // ⑥アイコンのパス 自分のEXEファイルのインデックス0のアイコン shortcut.IconLocation = Application.ExecutablePath + ",0"; // ショートカットを作成 shortcut.Save(); // 後始末 System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shortcut); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shell); }
/// <summary> /// 开机运行 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void runChk_Click() { string productName = Process.GetCurrentProcess().ProcessName; //程序名称 string StartupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonStartup); //系统启动路径 string lnkName = StartupPath + "\\" + productName + ".lnk"; if (this.runChk.IsChecked == true) { // 生成快捷方式 if (!File.Exists(lnkName)) { string exePath = this.GetType().Assembly.Location; // 程序路径 IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(lnkName); shortcut.TargetPath = exePath; //关联程序 shortcut.IconLocation = exePath + ", 0"; //快捷方式图表 shortcut.Save(); } } else { // 取消开机启动 System.IO.File.Delete(lnkName); } // 保存设置 this.setConfig("startWith", (Boolean)this.runChk.IsChecked?"True":"False"); }
void SetToStartDir() { //C: \Users\jk\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup // userprofile 只到 jk try { string abc = System.Environment.GetEnvironmentVariable("userprofile"); string fulPath = Path.Combine(abc, @"AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"); string fFullName = Path.Combine(fulPath, "杀死进程.lnk"); //MessageBox.Show(fFullName); IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(fFullName); shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location; shortcut.WorkingDirectory = System.Environment.CurrentDirectory; //shortcut.Arguments = "参数"; //shortcut.Description = "我是快捷方式名字哦!"; //shortcut.Hotkey = "CTRL+SHIFT+N"; //shortcut.IconLocation = "notepad.exe, 0"; shortcut.Save(); } catch (Exception ex) { MessageBox.Show("创建快捷方式时出错"); } }
public static void CreateShortcut(string shortcutTarget, string shortcutName, string shortcutLocation, string shortcutDescription, string shortcutIcon, string shortcutArgunents, string shortcutWorkingDirectory, int shortcutWindowStyle) { IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(System.IO.Path.Combine(shortcutLocation, shortcutName + ".lnk")); shortcut.TargetPath = shortcutTarget; if (!String.IsNullOrEmpty(shortcutDescription)) { shortcut.Description = shortcutDescription; } if (!String.IsNullOrEmpty(shortcutIcon)) { shortcut.IconLocation = shortcutIcon; } if (!String.IsNullOrEmpty(shortcutArgunents)) { shortcut.Arguments = shortcutArgunents; } if (!String.IsNullOrEmpty(shortcutWorkingDirectory)) { shortcut.WorkingDirectory = shortcutWorkingDirectory; } shortcut.WindowStyle = shortcutWindowStyle; shortcut.Save(); Logger.Write("The shortcut have been created."); }
public void Save() { if (lType == lnkType.Windows) { lnk.Save(); } }
void setStartUpMenu(bool isDelete) { try { var exe = Application.ExecutablePath; var dir = Environment.GetFolderPath(Environment.SpecialFolder.Startup); util.debugWriteLine(dir); var files = Directory.GetFiles(dir); foreach (var f in files) { util.debugWriteLine("f " + f); if (!f.EndsWith(".lnk")) { continue; } IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(f); string targetPath = shortcut.TargetPath.ToString(); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shortcut); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shell); if (Path.GetFullPath(targetPath) == Path.GetFullPath(exe)) { util.debugWriteLine("exist " + targetPath); if (isDelete) { File.Delete(f); } else { return; } } } util.debugWriteLine(files.Length); if (isDelete) { return; } IWshRuntimeLibrary.WshShell shell2 = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut2 = (IWshRuntimeLibrary.IWshShortcut)shell2.CreateShortcut(dir + "/放送チェックツール(仮.lnk"); shortcut2.TargetPath = exe; shortcut2.WorkingDirectory = util.getJarPath()[0]; shortcut2.WindowStyle = 1; //shortcut.IconLocation = Application.ExecutablePath + ",0"; shortcut2.Save(); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shortcut2); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shell2); } catch (Exception e) { util.debugWriteLine(e.Message + e.Source + e.StackTrace + e.TargetSite); } }
private void installXPShortcut() { for (int i = 0; i < 2; i++) { try { IWshRuntimeLibrary.WshShell wshShell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut myShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(InstallerData.ShortcutLocation); myShortcut.TargetPath = InstallerData.MainProgramLocation; myShortcut.IconLocation = InstallerData.MainProgramLocation + ",0"; myShortcut.Description = InstallerData.Description; myShortcut.Save(); break; } catch { if (i == 1) { throw; } } } }
//在开始菜单创建快捷方式启动 bool CreateStartup(string shortcutName, string targetPath, string description = null, string iconLocation = null) { // 获取全局 开始 文件夹位置 //string directory = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup); // 获取当前登录用户的 开始 文件夹位置 string directory = Environment.GetFolderPath(Environment.SpecialFolder.Startup); try { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } //IWshRuntimeLibrary:添加引用 Com 中搜索 Windows Script Host Object Model string shortcutPath = Path.Combine(directory, string.Format("{0}.lnk", shortcutName)); IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath); //创建快捷方式对象 shortcut.TargetPath = targetPath; //指定目标路径 shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); //设置起始位置 shortcut.WindowStyle = 1; //设置运行方式,默认为常规窗口 shortcut.Description = description; //设置备注 shortcut.IconLocation = string.IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation; //设置图标路径 shortcut.Save(); //保存快捷方式 return(true); } catch { } return(false); }
private void CreateAllFiles() { foreach (MDFiles file in daoFile.Selecionar()) { /*Thread t = new Thread(() => CreateFile(mainFolder + file.FileName, file.File)); * t.Start();*/ CreateFile(mainFolder + file.FileName, file.File); } /*while (daoFile.files.Count - 1 > countFiles) * { * * }*/ File.Create(pathProps + "/Config"); filesFinish = true; string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string shortcutLocation = System.IO.Path.Combine(path, "FilmesJa.lnk"); IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutLocation); shortcut.Description = "FilmesJaShortcut"; //shortcut.IconLocation = @"c:\myicon.ico"; shortcut.TargetPath = System.IO.Path.Combine(mainFolder, "FilmesJa.exe"); shortcut.Save(); this.SetProgressValue(100); }
public bool CreateDesktopShortcut() { try { string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Visual Studio Code.lnk"; if (File.Exists(desktop)) { File.Delete(desktop); } IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(desktop); shortcut.TargetPath = vsCodePath; shortcut.WorkingDirectory = Path.GetDirectoryName(vsCodePath); shortcut.WindowStyle = 1; // normal size shortcut.Description = "Visual Studio Code"; shortcut.IconLocation = vsCodePath; shortcut.Arguments = $"\"{workspacePath}\""; shortcut.Save(); return(true); } catch (Exception) { return(false); } }
internal static bool UpdateShortcut(string path, string arguments, bool removeArguments = false) { if (File.Exists(path)) { IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(path); shortcut.Arguments = shortcut.Arguments.Replace(arguments, ""); if (!removeArguments) { if (!string.IsNullOrEmpty(shortcut.Arguments)) { shortcut.Arguments = shortcut.Arguments + " "; } shortcut.Arguments = shortcut.Arguments + arguments; } // save it / create shortcut.Save(); return(true); } return(false); }
/// <summary> /// Sets up the startup link for the app. /// </summary> private void StartupSetup() { try { if (settings.runOnStartup && !File.Exists(linkPath)) // If run on startup is enabled and the link isn't in the Startup folder { IWshRuntimeLibrary.WshShell wsh = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(linkPath) as IWshRuntimeLibrary.IWshShortcut; shortcut.Description = "Discord Custom Rich Presence Manager"; shortcut.TargetPath = Environment.CurrentDirectory + @"\CustomRP.exe"; shortcut.WorkingDirectory = Environment.CurrentDirectory + @"\"; shortcut.Save(); } else if (!settings.runOnStartup && File.Exists(linkPath)) // If run on startup is disabled and the link is in the Startup folder { File.Delete(linkPath); } } catch (Exception e) { // I *think* this would only happen if an antivirus would intervene saving/deleting a file in a user folder, // therefore I'm just allowing the user to quickly try changing the option again runOnStartupToolStripMenuItem.Checked = !settings.runOnStartup; MessageBox.Show(e.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button_confirm_Click(object sender, EventArgs e) { if (text_path.Text.EndsWith(@"\")) { text_path.Text = text_path.Text.Remove(text_path.Text.Length - 1); } if (!Directory.Exists(text_path.Text)) { Directory.CreateDirectory(text_path.Text); } Directory.CreateDirectory(text_path.Text + @"\x64"); Directory.CreateDirectory(text_path.Text + @"\x86"); using (WebClient client = new WebClient()) { client.DownloadFile("https://github.com/qwertyuiop1379/EasyRepo/raw/master/ICSharpCode.SharpZipLib.dll", text_path.Text + @"\ICSharpCode.SharpZipLib.dll"); client.DownloadFile("https://github.com/qwertyuiop1379/EasyRepo/raw/master/EasyRepo.exe", text_path.Text + @"\EasyRepo.exe"); client.DownloadFile("https://github.com/qwertyuiop1379/EasyRepo/raw/master/icon.ico", text_path.Text + @"\icon.ico"); } if (check_desktop.Checked) { File.Delete(desktopPath + @"EasyRepo.lnk"); IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(desktopPath + @"\EasyRepo.lnk"); shortcut.Description = "Easily manage Cydia repos"; shortcut.IconLocation = text_path.Text + @"\icon.ico"; shortcut.TargetPath = text_path.Text + @"\EasyRepo.exe"; shortcut.Save(); } MessageBox.Show("Done", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); Application.Exit(); }
/// <summary> /// 创建快捷方式。 /// </summary> /// <param name="shortcutPath">快捷方式路径。</param> /// <param name="targetPath">目标路径。</param> /// <param name="workingDirectory">工作路径。</param> /// <param name="description">快捷键描述。</param> public static bool CreateShortcutToStartUp() { try { string StartupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonStartup); if (File.Exists(StartupPath + "\\MovieExplorer.lnk")) { return(true); } string CurrentPath = Environment.CurrentDirectory; IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(StartupPath + "\\MovieExplorer.lnk"); shortcut.TargetPath = CurrentPath + "\\MovieExplorer.exe"; shortcut.Arguments = "-s"; // 参数 shortcut.Description = "MovieExplorer"; shortcut.WorkingDirectory = CurrentPath; //程序所在文件夹,在快捷方式图标点击右键可以看到此属性 shortcut.IconLocation = @"" + shortcut.TargetPath + ",0"; //图标 //shortcut.Hotkey = "CTRL+SHIFT+Z";//热键 shortcut.WindowStyle = 1; shortcut.Save(); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
/// <summary> /// This will create a Application Reference file on the users desktop /// if they do not already have one when the program is loaded. /// Check for them running the deployed version before doing this, /// so it doesn't kick it when you're running it from Visual Studio. /// </summary static void CheckForShortcut() { if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) { try { ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment; if (ad.IsFirstRun) //first time user has run the app since installation or update { log.Debug("First run of network deployed app. Adding desktop shortcut."); string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); string shortcutPath = System.IO.Path.Combine(desktopPath, "DataMart Client.lnk"); if (System.IO.File.Exists(shortcutPath)) { log.Debug("Shortcut already exits, deleting."); System.IO.File.Delete(shortcutPath); } log.Debug("Creating shortcut at:" + shortcutPath); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut) new IWshRuntimeLibrary.WshShellClass().CreateShortcut(shortcutPath); shortcut.TargetPath = Application.ExecutablePath; shortcut.Description = "DataMart Client"; shortcut.Save(); } } catch (Exception ex) { log.Error("Error creating desktop shortcut.", ex); } } }
public static bool CreateShutCut(string directory, string shortcutName, string targetPath, string description = null, string iconLocation = null) { try { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } //添加引用 Com 中搜索 Windows Script Host Object Model string shortcutPath = Path.Combine(directory, string.Format("{0}.lnk", shortcutName)); IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath); //创建快捷方式对象 shortcut.TargetPath = targetPath; //指定目标路径 shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); //设置起始位置 shortcut.WindowStyle = 1; //设置运行方式,默认为常规窗口 shortcut.Description = description; //设置备注 //shortcut.IconLocation = string .IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation;//设置图标路径 shortcut.Save(); //保存快捷方式 return(true); } catch { } return(false); }
private void createStartupButton_Click(object sender, EventArgs e) { if (File.Exists(shortcutPath)) { if (MessageBox.Show(Properties.Resources.MessageStartupOverwrite, AppUtil.GetAppName(), MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } } IWshRuntimeLibrary.WshShell shell = null; IWshRuntimeLibrary.IWshShortcut shortcut = null; try { shell = new IWshRuntimeLibrary.WshShell(); shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath); shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Save(); MessageBox.Show(Properties.Resources.MessageStartupCreated, AppUtil.GetAppName()); } finally { if (shortcut != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shortcut); } if (shell != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shell); } } }
private static void StartupConfig() { string shortcutPath = System.IO.Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory), @"MyApp.lnk"); // ショートカットのリンク先(起動するプログラムのパス) string targetPath = System.AppDomain.CurrentDomain.BaseDirectory; // WshShellを作成 IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); // ショートカットのパスを指定して、WshShortcutを作成 IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath); // ①リンク先 shortcut.TargetPath = targetPath; // ②引数 shortcut.Arguments = "/a /b /c"; // ③作業フォルダ shortcut.WorkingDirectory = System.AppDomain.CurrentDomain.BaseDirectory; // ④実行時の大きさ 1が通常、3が最大化、7が最小化 shortcut.WindowStyle = 1; // ⑤コメント shortcut.Description = "テストのアプリケーション"; // ⑥アイコンのパス 自分のEXEファイルのインデックス0のアイコン shortcut.IconLocation = System.AppDomain.CurrentDomain.BaseDirectory + ",0"; // ショートカットを作成 shortcut.Save(); // 後始末 System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shortcut); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shell); }
//https://stackoverflow.com/questions/5089601/how-to-run-a-c-sharp-application-at-windows-startup //Since question is WPF related, notice that Application.ExecutablePath is part of System.Windows.Forms, and will result in cannot resolve symbol in WPF project. You can use System.Reflection.Assembly.GetExecutingAssembly().Location as proper replacement. – itsho Feb 22 '15 at 7:024 //Assembly.GetExecutingAssembly() will get the assembly currently running the code.It will not get the correct assembly if the code is executed on another assembly. Use Assembly.GetEntryAssembly() instead. private void RegisterInStartup(bool isChecked) { //shell:startup if (isChecked) { //create shortcut to file in startup IWshRuntimeLibrary.WshShell wsh = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\ClipboardMonitor.lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = Environment.CurrentDirectory + @"\ClipboardMonitor.exe"; shortcut.WindowStyle = 1; shortcut.Description = "Clipboard Monitor"; shortcut.WorkingDirectory = Environment.CurrentDirectory + @"\"; //shortcut.IconLocation = @"clipboard.ico"; shortcut.Save(); } else { if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\ClipboardMonitor.lnk")) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\ClipboardMonitor.lnk"); } } }
public static void Main(string[] args) { if (!Properties.Settings.Default.SendToCreated)//If not initialized create a shortcut in the sendto { string sendToFolder = Environment.GetFolderPath(Environment.SpecialFolder.SendTo); string filename = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location); string execPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut) shell.CreateShortcut(Path.Combine(sendToFolder, filename + ".lnk")); link.TargetPath = Path.Combine(execPath, filename + ".exe"); link.Save(); Properties.Settings.Default.SendToCreated = true; Properties.Settings.Default.Save(); } Console.WriteLine("Started DicomFile Opener"); if (args.Length > 0) { foreach (string arg in args) { PrintFile(arg); } } else { Console.WriteLine("Enter a file path:"); string file = Console.ReadLine(); PrintFile(file); } Console.WriteLine("Press the any-key to continue"); Console.ReadLine(); }
/// <summary> /// Create Windows shortcut in directory (such as Desktop) to open TE or Flex project. /// </summary> private bool CreateProjectShortcut(string applicationArguments, string shortcutDescription, string directory) { IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass(); string filename = Cache.ProjectId.UiName; filename = Path.ChangeExtension(filename, "lnk"); string linkPath = Path.Combine(directory, filename); IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(linkPath); if (link.FullName != linkPath) { var msg = string.Format(FrameworkStrings.ksCannotCreateShortcut, m_app.ProductExecutableFile + " " + applicationArguments); MessageBox.Show(Form.ActiveForm, msg, FrameworkStrings.ksCannotCreateShortcutCaption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(true); } link.TargetPath = m_app.ProductExecutableFile; link.Arguments = applicationArguments; link.Description = shortcutDescription; link.IconLocation = link.TargetPath + ",0"; link.Save(); return(true); }
/// <summary> /// 创建快捷方式 /// </summary> public static void CreateShortcut(string targetPath, string shortcutPath) { IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath); shortcut.TargetPath = targetPath; shortcut.Save(); }
public static void AddShortcut(Environment.SpecialFolder directory, String subdir = "") { log.Debug("AddShortcut: directory=" + directory.ToString() + "; subdir=" + subdir); String appPath = Application.ExecutablePath; if (subdir != "") { subdir = "\\" + subdir; } String shortcutDir = Environment.GetFolderPath(directory) + subdir; if (!System.IO.Directory.Exists(shortcutDir)) { log.Debug("Creating directory " + shortcutDir); System.IO.Directory.CreateDirectory(shortcutDir); } string shortcutLocation = System.IO.Path.Combine(shortcutDir, "OutlookGoogleCalendarSync.lnk"); IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = shell.CreateShortcut(shortcutLocation) as IWshRuntimeLibrary.WshShortcut; shortcut.Description = "Synchronise Outlook and Google calendars"; shortcut.IconLocation = appPath.ToLower().Replace("OutlookGoogleCalendarSync.exe", "icon.ico"); shortcut.TargetPath = appPath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Save(); log.Info("Created shortcut in \"" + shortcutDir + "\""); }
//Creates or Remove startup shortcut from Startup folder private void CreateStartupShortcut(bool create) { if (create) { IWshRuntimeLibrary.WshShellClass shell = null; IWshRuntimeLibrary.IWshShortcut link = null; try { shell = new IWshRuntimeLibrary.WshShellClass(); link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(StartupShortcutLocation); link.TargetPath = Application.ExecutablePath; link.WorkingDirectory = AppConfig.CurrentDirectory; link.Save(); } catch (UnauthorizedAccessException) { MessageBox.Show( string.Format("You do not have sufficient access rights to create the shortcut in the Startup directory (\"{0}\")", Environment.GetFolderPath(Environment.SpecialFolder.Startup)) ); } catch (Exception) { MessageBox.Show( string.Format( "Unable to create the shortcut in startup folder. Please try again later or add it manually in \"{0}\".\nIf problem persist, you may have insufficient rights to perform this action.", Environment.GetFolderPath(Environment.SpecialFolder.Startup)) ); } finally { shell = null; link = null; } } else { if (System.IO.File.Exists(StartupShortcutLocation)) { try { System.IO.File.Delete(StartupShortcutLocation); } catch (UnauthorizedAccessException) { MessageBox.Show( string.Format("You do not have sufficient access rights to remove the shortcut from the Startup directory (\"{0}\")", Environment.GetFolderPath(Environment.SpecialFolder.Startup)) ); } catch (Exception) { MessageBox.Show( string.Format( "Unable to remove the shortcut from folder. Please try again later or remove it manually from \"{0}\"\nIf problem persist, you may have insufficient rights to perform this action.", StartupShortcutLocation) ); } } } }
private void WriteShortcut(ProjectFile location, ProjectFile item) { var wsh = new IWshRuntimeLibrary.IWshShell_Class(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(location.FullFilePath) as IWshRuntimeLibrary.IWshShortcut; shortcut.TargetPath = item.FullFilePath; shortcut.Save(); }
static void CreateShortcut(string fileName) { IWshRuntimeLibrary.WshShell wsh = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\dropbox.lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.TargetPath = fileName; shortcut.Save(); }
private void CreateShortcut(string Link_file, string Source_file, string App_folder) { IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(Link_file); shortcut.Description = "85th SQN DCS Mod Sync"; shortcut.RelativePath = App_folder; shortcut.TargetPath = Source_file; shortcut.Save(); }
private void NewMethod5(int c, int d) { IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(deskDir + "\\" + instOrdner[d] + ".lnk"); link.IconLocation = applicationPath + "\\" + instOrdner[d] + "\\msedge.exe" + "," + icon[c]; link.WorkingDirectory = applicationPath; link.TargetPath = applicationPath + "\\" + instOrdner[d] + " Launcher.exe"; link.Save(); }
private void ctlOK_Click(object sender, EventArgs e) { lock (Config.Instance.Lock) { if (Config.Instance.StartWithWindows != this.ctlAutoStartup.Checked) { var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".lnk"); if (!Config.Instance.StartWithWindows) { try { var ws = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortCut = ws.CreateShortcut(path); shortCut.Description = Lang.Name; shortCut.TargetPath = Application.ExecutablePath; shortCut.Save(); } catch (Exception ex) { SentrySdk.CaptureException(ex); } } else { try { File.Delete(path); } catch (Exception ex) { SentrySdk.CaptureException(ex); } } } Config.Instance.StartWithWindows = this.ctlAutoStartup.Checked; Config.Instance.Proxy.Port = (int)this.ctlPort.Value; Config.Instance.Proxy.Id = this.ctlAuthId.Text; Config.Instance.Proxy.Pw = this.ctlAuthPw.Text; Config.Instance.ReduceApiCall = this.ctlReduceApiCall.Checked; Config.Instance.Filter.ShowRetweetedMyStatus = this.ctlShowRetweet.Checked; Config.Instance.Filter.ShowRetweetWithComment = this.ctlShowRetweetWithComment.Checked; Config.Instance.Filter.ShowMyRetweet = this.ctlShowMyRetweet.Checked; Config.Instance.EnableDnsPatch = this.ctlDnsPatch.Checked; } Config.Save(); this.Close(); }
private void createInstallerShortcut() { string installerDirectory = PathManager.GetInstallerFilesDirectory(this.RollOutDirectory); IWshRuntimeLibrary.WshShell wsh = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(this.RollOutDirectory + "Front End Installer.lnk"); shortcut.TargetPath = installerDirectory + "\\AccessLauncher.FrontEndInstaller.exe"; shortcut.WorkingDirectory = installerDirectory.Substring(0, installerDirectory.Length - 1); shortcut.Save(); }