c# 登陆后自动运行

RegistryKey KeyCon=Registry.LocalMachine.OpenSubKey( "Software\\Microsoft\\Windows\\CurrentVersion\\Run",true);

 string MyKey= "Terminal";

if((string)KeyCon.GetValue(MyKey,"no") == "no")//指定的键不存在

{ string Path = Application.StartupPath+@"\Terminal.exe"; KeyCon.SetValue(MyKey,Path);

 //设置注册表中的启动键 }

-------------

 //如果要取消的话就将KeyCon.SetValue(MyKey,Path);改成     

//KeyCon.SetValue(MyKey,false);

--说明:由于放在注册表 run中,用户必须登陆后才执行。
若在服务器上,机器重启,则不能使用该方式,要采用windows服务方式。

原文地址:https://www.cnblogs.com/xinyuxin912/p/1331306.html