1 #region 开机自启
2 /// <summary>
3 /// 开机自启创建
4 /// </summary>
5 /// <param name="exeName">程序名称</param>
6 /// <returns></returns>
7 public bool StartAutomaticallyCreate(string exeName)
8 {
9 try
10 {
11 WshShell shell = new WshShell();
12 IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\" + exeName + ".lnk");
13 //设置快捷方式的目标所在的位置(源程序完整路径)
14 shortcut.TargetPath = System.Windows.Forms.Application.ExecutablePath;
15 //应用程序的工作目录
16 //当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
17 shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
18 //目标应用程序窗口类型(1.Normal window普通窗口,3.Maximized最大化窗口,7.Minimized最小化)
19 shortcut.WindowStyle = 1;
20 //快捷方式的描述
21 shortcut.Description = exeName + "_Ink";
22 //设置快捷键(如果有必要的话.)
23 //shortcut.Hotkey = "CTRL+ALT+D";
24 shortcut.Save();
25 return true;
26 }
27 catch (Exception) { }
28 return false;
29 }
30 /// <summary>
31 /// 开机自启删除
32 /// </summary>
33 /// <param name="exeName">程序名称</param>
34 /// <returns></returns>
35 public bool StartAutomaticallyDel(string exeName)
36 {
37 try
38 {
39 System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\" + exeName + ".lnk");
40 return true;
41 }
42 catch (Exception) { }
43 return false;
44 }
45 #endregion