c# 开机启动项的小例子
//路径, 添加开机启动/删除开机启动
public static void setautorun(string filename, bool isautorun)
{
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);
}
catch (exception ex)
{
throw new exception(ex.tostring());
}
finally
{
if (reg != null)
reg.close();
}
}