winform程序中 如何添加代码,让软件在开机后自启动???
解决方案 »
- .net的普通的winform程序,有个设置成开机自启动怎么实现
- 有人做过类似visual studio的控件操作,界面上有控件栏,有属性栏,控件拖到界面后支持常见的操作
- 类库中类的调用?
- 有个大胆的问题想问问大家?
- VS2005 Ext2.0 问题 好难找的哦
- 50求参数传递
- 制作随机启动程序,并每隔一段时间对数据库表进行操作!急
- 内部查询处理器错误!怎么回事情呀!语句在SQL2000查询分析器中执行正常!
- 将string插入sql srver表中text类型字段,太长时无法插入,怎么办?
- 散分:按概率取值问题的算法。
- C# 中文分词技术有哪些?
- 调用 Dll "试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)
key.SetValue(程序的名称, 程序的路径);
或
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);
添加Windows计划任务
或者是设置系统服务,自启动
{
RegistryKey reg = null;
try
{
if (!System.IO.File.Exists(fileName))
throw new Exception("该文件不存在!");
String name = fileName.Substring(fileName.LastIndexOf(@"\") + 1);
reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
if (reg == null)
reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
if (isAutoRun)
reg.SetValue(name, fileName);
else
reg.SetValue(name, false);
lbl_autorunerr.Visible = false;
}
catch
{
lbl_autorunerr.Visible = true;
//throw new Exception(ex.ToString());
}
finally
{
if (reg != null)
reg.Close();
}
}
使用的时候,直接调用SetAutoRun函数即可,这里解释一下两个参数的含义:fileName:需要设置自动启动程序的路径,若为当前程序可直接传递Application.ExecutablePath。isAutoRun:是否自动运行,为false时,取消自动运行。例: SetAutoRun(Application.ExecutablePath, true); //设置自动启动当前程序 SetAutoRun(Application.ExecutablePath, false); //取消自动启动
复制程序-》粘贴程序到“C:\Documents and Settings\Administrator\「开始」菜单\程序\启动”目录下-》搞定
恩 具体编程嘛 就是比如c#:
API 中的CopyFile函数搞定。
取消自启动嘛更简单 删掉OK.
开机自动启动程序的函数:public void SetAutoRun(string fileName, bool isAutoRun)
{
RegistryKey reg = null;
try
{
if (!System.IO.File.Exists(fileName))
throw new Exception("该文件不存在!")……