zoukankan
html css js c++ java
将程序加到启动组
将程序加到启动组
有时需要将程序设置成随系统启动,最简单的一种就是放在 程序-->启动组里面。
其实就是创建一个快捷方式而已, 呵呵
我们需要一个 com 组件, 名叫 "Window Script Host Object Model ", 将它加入引用中
代码就很简单了, 为了方便调用, 将它写成一个函数
/**/
///
<summary>
///
将程序的快捷方式添加到启动组
///
</summary>
///
<param name="fullPath">
程序全路径
</param>
private
void
AddShortCutToStartup(
string
fullPath)
{
if
(
string
.IsNullOrEmpty(fullPath))
return
;
IWshRuntimeLibrary.WshShell shell
=
new
IWshRuntimeLibrary.WshShell();
try
{
//
取得快捷方式的路径
//
快捷方式其实是一个后缀为 lnk 的文件
string
link
=
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup)
, Path.GetFileNameWithoutExtension(fullPath)
+
"
.lnk
"
);
if
(
!
File.Exists(link))
{
IWshRuntimeLibrary.IWshShortcut shortCut
=
(IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(link);
//
设置目标路径
//
shortCut 还有很多方法,比如 HotKey, IconLocation 等等,不再赘述
shortCut.TargetPath
=
fullPath;
shortCut.WindowStyle
=
1
;
shortCut.Save();
}
}
catch
(Exception ex)
{
log.Error(
"
AddShortCutToStartup Error:
"
+
ex.Message);
}
}
如果要将本程序做成自启动, 只需要在 Form_Load 中加一行代码就行了
AddShortCutToStartup(Application.ExecutablePath);
作者:
观海看云
(
个人开发历程知识库 - 博客园
)
出处:
http://www.cnblogs.com/zhangtao/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
查看全文
相关阅读:
java中<> 的用法
Java 中 compareTo方法问题
class AClass<E extends Comparable>与class AClass<E extends Comaprable<E>>有什么区别?
zookeeper常用命令
Storm概念讲解和工作原理介绍
Storm集群安装部署步骤【详细版】
Error contacting service. It is probably not running.
Exception in thread "main" expected '<document start>', but found BlockMappingStart in 'reader', line 23, column 2: nimbus.host: "master"
zookeeper 启动失败 BindException: Address already in use 或者Error contacting service. It is probably not running
scss的安装使用
原文地址:https://www.cnblogs.com/zhangtao/p/1516717.html
最新文章
推荐的有些东东
shell 数组
shell awk
json格式化工具
精确率与召回率
python机器学习库
hadoop-streaming 配置之---参数分割
关于
统计学视频
servlet中请求转发(forword)与重定向(sendredirect)的区别
热门文章
JSP+JavaBean+Servlet实现各类列表分页功能
JSP+Servlet+javabean+mysql实现页面多条件模糊查询
数据库中读取出0或1,页面显示禁用或正常
JSTL的if-else表式
请求servlet操作成功后,在JSP页面弹出提示框
使用onclick跳转到其他页面/跳转到指定url
resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found.
执行查询报: Incorrect key file for table ‘test’; try to repair it
JSP表单提交中文乱码解决方案
常见数据结构与算法整理总结(上)
Copyright © 2011-2022 走看看