C#代码实现开机启动是我的界面 请看到帖子的资深人士帮忙解答一下,希望是用代码实现的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ?什么情况?替换windows登录时的壁纸?还是像瑞星一样在登录前就挂个程序?还是仅仅是开机启动程序?如果是第三个,这代码够用了string starupPath = Application.ExecutablePath;RegistryKey loca = Registry.LocalMachine;RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); try { run.SetValue("开机启动", starupPath); MessageBox.Show("注册表添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); loca.Close(); run.Close(); } catch (Exception ee) { MessageBox.Show(ee.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } 是不是设置开机启动你的程序?public static bool SetAutoRun(string keyName,string filePath) { try { RegistryKey runKey=Registry.LocalMachine.OpenSubKey(@"\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true); runKey.SetValue(keyName,filePath); runKey.Close(); } catch { return false; } return true; }调用:第一个参数:起个名字而已 第二个参数:你的程序的全路径 SetAutoRun("myexe","c:\\text.exe"); 或者copy你的程序的快捷方式到C:\Documents and Settings\Administrator\「开始」菜单\程序\启动 public enum AutorunType{ LocalMachineRun, CurrentUserRun, LocalMachineShell}public static void DisableApplicationAutorun(string displayName, AutorunType autorunType) { if (autorunType == AutorunType.LocalMachineShell) { Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"); regKey.SetValue("Shell", "Explorer.exe"); regKey.Close(); } else if (autorunType == AutorunType.LocalMachineRun) { Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run"); regKey.DeleteValue(displayName, false); regKey.Close(); } else if (autorunType == AutorunType.CurrentUserRun) { Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run"); regKey.DeleteValue(displayName, false); regKey.Close(); } }public static void EnableApplicationAutorun(string displayName, string programFullPathFileName, AutorunType autorunType) { if (autorunType == AutorunType.LocalMachineShell) { Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"); regKey.SetValue("Shell", "Explorer.exe " + programFullPathFileName); regKey.Close(); } else if (autorunType == AutorunType.LocalMachineRun) { Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run"); regKey.SetValue(displayName, programFullPathFileName, Microsoft.Win32.RegistryValueKind.String); regKey.Close(); } else if (autorunType == AutorunType.CurrentUserRun) { Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run"); regKey.SetValue(displayName, programFullPathFileName, Microsoft.Win32.RegistryValueKind.String); regKey.Close(); } } 请问怎么报错啊!:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(21,41): 错误 CS0117: “System.Windows.Forms.Application”并不包含“ExecutablePath”的定义E:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(22,9): 错误 CS0246: 找不到类型或命名空间名称“RegistryKey”(是否缺少 using 指令或程序集引用?)E:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(22,28): 错误 CS0103: 当前上下文中不存在名称“Registry”E:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(23,9): 错误 CS0246: 找不到类型或命名空间名称“RegistryKey”(是否缺少 using 指令或程序集引用?)E:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(27,80): 错误 CS0117: “System.Windows.Forms.MessageBoxIcon”并不包含“Information”的定义E:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(33,92): 错误 CS0117: “System.Windows.Forms.MessageBoxIcon”并不包含“Error”的定义 win7系统 为什么装不上Visual Studio 2010旗舰版 非常感谢! 数据源如何更新 WindowsXP开发程序到Windows7运行兼容问题 是否可以将指定方法锁定,同一时间只能有一人使用此方法? 更新按钮局部刷新问题? 请教正则表达式 请教高手HTML页面怎么转换成横版的WORD? C#连接外接显示屏 图片上传并进行格式的判断 使用HttpWebRequest和HttpWebResponse下载文件时出现超时情况如何处理? 通过WebBrowser获得网站上的数据 如何在mdi窗体中运行其他程序
如果是第三个,这代码够用了
string starupPath = Application.ExecutablePath;
RegistryKey loca = Registry.LocalMachine;
RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
try
{
run.SetValue("开机启动", starupPath);
MessageBox.Show("注册表添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
loca.Close();
run.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
public static bool SetAutoRun(string keyName,string filePath)
{
try
{
RegistryKey runKey=Registry.LocalMachine.OpenSubKey(@"\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true);
runKey.SetValue(keyName,filePath);
runKey.Close();
}
catch
{
return false;
}
return true;
}调用:第一个参数:起个名字而已
第二个参数:你的程序的全路径
SetAutoRun("myexe","c:\\text.exe");
C:\Documents and Settings\Administrator\「开始」菜单\程序\启动
public enum AutorunType
{
LocalMachineRun, CurrentUserRun, LocalMachineShell
}public static void DisableApplicationAutorun(string displayName, AutorunType autorunType) {
if (autorunType == AutorunType.LocalMachineShell)
{
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon");
regKey.SetValue("Shell", "Explorer.exe");
regKey.Close();
}
else if (autorunType == AutorunType.LocalMachineRun)
{
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
regKey.DeleteValue(displayName, false);
regKey.Close();
}
else if (autorunType == AutorunType.CurrentUserRun)
{
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
regKey.DeleteValue(displayName, false);
regKey.Close();
}
}public static void EnableApplicationAutorun(string displayName, string programFullPathFileName, AutorunType autorunType) {
if (autorunType == AutorunType.LocalMachineShell) {
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon");
regKey.SetValue("Shell", "Explorer.exe " + programFullPathFileName);
regKey.Close();
}
else if (autorunType == AutorunType.LocalMachineRun) {
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
regKey.SetValue(displayName, programFullPathFileName, Microsoft.Win32.RegistryValueKind.String);
regKey.Close();
}
else if (autorunType == AutorunType.CurrentUserRun) {
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
regKey.SetValue(displayName, programFullPathFileName, Microsoft.Win32.RegistryValueKind.String);
regKey.Close();
}
}
:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(21,41): 错误 CS0117: “System.Windows.Forms.Application”并不包含“ExecutablePath”的定义
E:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(22,9): 错误 CS0246: 找不到类型或命名空间名称“RegistryKey”(是否缺少 using 指令或程序集引用?)
E:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(22,28): 错误 CS0103: 当前上下文中不存在名称“Registry”
E:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(23,9): 错误 CS0246: 找不到类型或命名空间名称“RegistryKey”(是否缺少 using 指令或程序集引用?)
E:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(27,80): 错误 CS0117: “System.Windows.Forms.MessageBoxIcon”并不包含“Information”的定义
E:\工作代码文件\DeviceApplication2\DeviceApplication2\Program.cs(33,92): 错误 CS0117: “System.Windows.Forms.MessageBoxIcon”并不包含“Error”的定义