用C#写的window窗体应用程序,怎样让它在开机的时候自动启动?

如题所述

! private void 启用ToolStripMenuItem_Click(object sender, EventArgs e) { //获取程序执行路径.. string starupPath = Application.ExecutablePath; //class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装. RegistryKey loca = Registry.LocalMachine; RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); try { //SetValue:存储值的名称 run.SetValue("kaixin", starupPath); MessageBox.Show("已启用开机运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); loca.Close(); } catch (Exception ee) { MessageBox.Show(ee.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } regset();//获取注册表状态 } private void 停用ToolStripMenuItem_Click(object sender, EventArgs e) { //获取程序执行路径.. string starupPath = Application.ExecutablePath; //class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装. RegistryKey loca = Registry.LocalMachine; RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); try { //SetValue:存储值的名称 run.DeleteValue("kaixin"); MessageBox.Show("已停止开机运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); loca.Close(); } catch (Exception ee) { MessageBox.Show(ee.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } regset();//获取注册表状态 } private void regset() { //获取程序执行路径.. string starupPath = Application.ExecutablePath; //class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装. RegistryKey loca = Registry.LocalMachine; RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); string[] subkeyNames; subkeyNames = run.GetValueNames(); foreach (string keyName in subkeyNames) { if (keyName == "kaixin") { this.开机运行ToolStripMenuItem.Text = "开机运行(启动中)"; this.启用ToolStripMenuItem.Enabled = false; this.停用ToolStripMenuItem.Enabled = true; } else { this.开机运行ToolStripMenuItem.Text = "开机运行(已停止)"; this.启用ToolStripMenuItem.Enabled = true; this.停用ToolStripMenuItem.Enabled = false; } } }
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网