2023年11月27日发(作者:)
原理就是在注册表启动项里添加一项。
路径:
SOFTWAREMicrosoftWindowsCurrentVersionRun
或者直接:运行->regedit找到这个路径添加一项。
using System;
using c;
using entModel;
using ;
using g;
using ;
using ;
using ;
{
public Form1()
{
InitializeComponent();
}
private void btnSet_Click(object sender, EventArgs e)
{
SetAutoRun(@"D:",true);
}
///
/// 设置应用程序开机自动运行
///
/// 应用程序的文件名
/// 是否自动运行,为false时,取消自动运行
///
public static void SetAutoRun(string fileName, bool isAutoRun)
{
RegistryKey reg = null;
try
{
if (!(fileName))
throw new Exception("该文件不存在!");
String name = ing(dexOf(@"") + 1);
reg = bKey(@"SOFTWAREMicrosoftWindows
CurrentVersionRun", true);
if (reg == null)
reg = SubKey(@"SOFTWAREMicrosoftWind
owsCurrentVersionRun");
if (isAutoRun)
ue(name, fileName);
else
ue(name, false);
}
catch (Exception ex)
{
throw new Exception(ng());
}
finally
{
if (reg != null)
();
}
}
//另外也可以写成服务,不过服务的话一般是在后台执行的,没有程序界面。
}
}
或者直接:
开机自启
public static bool SetAutoRun(string keyName,string filePath)
{
try
{
RegistryKey
urrentVersionRun",true);
ue(keyName,filePath);
();
}
catch
{
return false;
}
return true;
}
test: SetAutoRun("myexe","c:");
runKey=bKey(@"SOFTWAREMicrosoftWindowsC
{
System.sStartInfo info=new
System.sStartInfo();
llExecute = true;
Process p;
string path = @"C:";
FileStream fs = new FileStream(path, , );
StreamReader sr = new StreamReader(fs, t);
string rl;
while ((rl = sr.ReadLine()) != null)
{
me = rl;
//Text(rl + 'n');
p = (info);
}
sr.Close();
();
();
}
}
}
使用说明:先安装好软件,20多K吧,运行前先在c盘根目录建立一个,然后把需要同
时运行的程序详细路径,包括程序名和exe后缀,一个程序占一行,可以同时有多行,例如:
C:Program FilesInternet
C:Program FilesInternet


发布评论