WPF-开机自启

 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

 

转载于:https://www.cnblogs.com/liuph/p/5195565.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值