现在的位置: 首页 > 综合 > 正文

用c#实现开机自动运行

2013年08月05日 ⁄ 综合 ⁄ 共 515字 ⁄ 字号 评论关闭

 从前用native API实现过程序开机自动运行,前几天刚好要用到,就用
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); //设置注册表中的启动键
}
MainForm mw = new MainForm();

顺便记录下用c#实现全屏(不带任务栏)的简单方法。

this.FormBorderStyle = FormBorderStyle.None;   //设置窗口边框

this.WindowState = FormWindowState.Maximized;   //设置程序最大化

注:当然也可以在窗口属性中设置这两个属性值。 

抱歉!评论已关闭.