C#中设置开机自动运行和关机
来源:互联网 发布:mac快速回到桌面快捷键 编辑:程序博客网 时间:2024/05/22 08:10
让软件开机自动运行或者设置自动关机,大部分软件都有这种功能。如何实现呢,其实很简单,开机运行,只需要设置注册表就可以了,关机则调用CMD命令:shutdown -s -t,如下:
开机自动运行:
/// <summary> /// 设置开机运行 /// </summary> public void AutoRun() { RegistryKey runItem = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true); if (runItem == null) { run.SetValue("exe的名字","exe的路径"); } } /// <summary> /// 取消开机运行 /// </summary> public void DeleteAutoRun() { RegistryKey runItem = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true); if (runItem != null) { runItem.DeleteSubKey("exe的名字"); } }
设置关机:
public static string ExecuteCmd(string command) { string output = ""; //输出字符串 if (command != null && !command.Equals("")) { Process process = new Process();//创建进程对象 ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "cmd.exe";//设定需要执行的命令 startInfo.Arguments = "/C " + command;//“/C”表示执行完命令后马上退出 startInfo.UseShellExecute = false;//不使用系统外壳程序启动 startInfo.RedirectStandardInput = false;//不重定向输入 startInfo.RedirectStandardOutput = true; //重定向输出 startInfo.CreateNoWindow = true;//不创建窗口 process.StartInfo = startInfo; process.Start(); } }
调用:
ExecuteCmd("shutdown -s -t");
- C#中设置开机自动运行和关机
- C#中设置开机自动运行和关机
- C# 设置应用程序开机自动运行
- C# 设置应用程序开机自动运行
- 设置开机自动运行
- C#操作注册表及设置开机自动运行
- C#操作注册表及设置开机自动运行
- c#设置软件开机自动运行,修改注册表
- c#设置软件开机自动运行,修改注册表
- buildroot设置开机自动运行程序和自动登录
- linux开机自动运行设置
- linux开机自动运行设置
- VC 设置开机自动运行
- linux开机自动运行设置 .
- VC 设置开机自动运行
- 设置开机自动运行vncserver
- 电脑自动开机和关机的方法
- C# WinForm 开机自动运行
- 赋值操作为何返回引用
- 知道自己不足了
- POJ-3041 Asteroids
- simhash进行文本查重
- 短信网关平台ESMG7.3版性能测试报告
- C#中设置开机自动运行和关机
- Hibernate关系映射详解
- 交叉编译工具链
- servlet下载文件名称乱码
- Z-Blog的资源下载中心
- 二项堆(减小关键字的值和删除指定关键字)
- C#判断中文 日文 韩文
- QT学习6:组装丰富的积木!
- The type 类名 is already defined