通过获取命令行参数来判断他是不是开机启动 还是双机启动
String commandLineString = System.Environment.CommandLine;
String[] args = System.Environment.GetCommandLineArgs();
添加开机启动
try { string exeDir = Application.ExecutablePath + " " + tb_pass.Text; RegistryKey rk = Registry.LocalMachine; RegistryKey softWare = rk.OpenSubKey("SOFTWARE"); RegistryKey microsoft = softWare.OpenSubKey("Microsoft"); RegistryKey windows = microsoft.OpenSubKey("Windows"); RegistryKey current = windows.OpenSubKey("CurrentVersion"); RegistryKey run = current.OpenSubKey(@"Run", true); run.SetValue("ScreenLock", exeDir); } catch (Exception ex) { Console.WriteLine(ex.ToString()); }
取消开机启动
try { RegistryKey rk = Registry.LocalMachine; RegistryKey softWare = rk.OpenSubKey("Software"); RegistryKey microsoft = softWare.OpenSubKey("Microsoft"); RegistryKey windows = microsoft.OpenSubKey("Windows"); RegistryKey current = windows.OpenSubKey("CurrentVersion"); RegistryKey run = current.OpenSubKey(@"Run", true); run.DeleteValue("ScreenLock"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); }
通过全局钩子来屏蔽一些按键
源代码下载地址:http://download.csdn.net/detail/xzh1995/6534905