




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
原理就是在注册表启动项里添加一项。路径:SOFTWAREMicrosoftWindowsCurrentVersionRun或者直接:运行-regedit找到这个路径添加一项。usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingMicrosoft.Win32;namespaceCSharpStartpublicpartialclassForm1:FormpublicForm1()InitializeComponent();privatevoidbtnSet_Click(objectsender,EventArgse)SetAutoRun(D:CSharpStart.exe,true);/设置应用程序开机自动运行/应用程序的文件名/是否自动运行,为false时,取消自动运行/设置不成功时抛出异常publicstaticvoidSetAutoRun(stringfileName,boolisAutoRun)RegistryKeyreg=null;tryif(!System.IO.File.Exists(fileName)thrownewException(该文件不存在!);Stringname=fileName.Substring(fileName.LastIndexOf()+1);reg=Registry.LocalMachine.OpenSubKey(SOFTWAREMicrosoftWindowsCurrentVersionRun,true);if(reg=null)reg=Registry.LocalMachine.CreateSubKey(SOFTWAREMicrosoftWindowsCurrentVersionRun);if(isAutoRun)reg.SetValue(name,fileName);elsereg.SetValue(name,false);catch(Exceptionex)thrownewException(ex.ToString();finallyif(reg!=null)reg.Close();/另外也可以写成服务,不过服务的话一般是在后台执行的,没有程序界面。或者直接:1. /添加启动2. RegistryKeyms_run=Registry.LocalMachine.OpenSubKey(SOFTWARE/Microsoft/Windows/CurrentVersion/Run,true);3. ms_run.SetValue(mistysoft,Application.ExecutablePath.ToString();4. /删除启动(设为控,注册表项还在)5. RegistryKeyms_run=Registry.LocalMachine.OpenSubKey(SOFTWARE/Microsoft/Windows/CurrentVersion/Run,true);6. ms_run.SetValue(mistysoft,);开机自启publicstaticboolSetAutoRun(stringkeyName,stringfilePath) try RegistryKey runKey=Registry.LocalMachine.OpenSubKey(SOFTWAREMicrosoftWindowsCurrentVersionRun,true); runKey.SetValue(keyName,filePath); runKey.Close(); catch returnfalse; returntrue; test: SetAutoRun(myexe,c:text.exe);另一个实例:宿舍的肥仔每次开机就需要运行多个程序,他希望一个程序实现这些事情,所以写了个程序,大家有什么意见可以给我提出来,我会多加修改,谢谢,贴上源码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Diagnostics;using System.IO;namespace 懒人程序 public partial class Form1 : Form public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) System.Diagnostics.ProcessStartInfo info=new System.Diagnostics.ProcessStartInfo(); info.UseShellExecute = true; Process p; string path = C:a.txt; FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs, Encoding.Default); string rl; while (rl = sr.ReadLine() != null) info.FileName = rl; /richTextBox1.AppendText(rl + n); p = Process.Start(info); sr.Close(); fs.Close(); Application.Exit(); 使用说明:先安装好软件,20多K吧,运行前先在c盘根目录建立一个a.txt,然
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 农业生产智能化技术推广方案
- 2026届河南省开封市重点名校化学高二第一学期期末质量跟踪监视模拟试题含答案
- 能源行业智能电网智能巡检方案
- IT系统架构设计与实现实战指南
- 小学一年级语文知识拓展补差计划
- 秋季幼儿园膳食预算控制计划
- 装饰装修工程质量保证体系及职工技能提升措施
- (2025年标准)股权转让风险协议书
- 商业合作发展策略协议书
- 2025届高三物理分层教学复习计划
- 七年级班主任开学第一课课件
- XXX有限公司报销审核制度
- WS/T 427-2013临床营养风险筛查
- GA/T 1047-2013道路交通信息监测记录设备设置规范
- GJB9001C内审员培训讲学课件
- 五牌一图(完整版)
- 幼儿园绘本故事:《十二生肖》 课件
- 激光跟踪仪使用手册
- 新媒体运营知识考核试题与答案
- 金属材料的主要性能ppt课件(完整版)
- 丽声北极星自然拼读绘本第二级 Fat Cat 课件
评论
0/150
提交评论