C# 32位程序自動判斷當(dāng)前操作系統(tǒng)是32位/64位版本并更改注冊表實現(xiàn)自動登錄Windows和開啟某個程序
當(dāng)前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Win32; //判斷操作系統(tǒng)版本(64位\32位)打開注冊表項 RegistryKey localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32); //開機(jī)自動進(jìn)入Windows RegistryKey sub_key0 = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true); if (this.chk_auto_login_windows.Checked == true) { sub_key0.SetValue("AutoAdminLogon", "1"); sub_key0.SetValue("DefaultDomainName", ""); sub_key0.SetValue("DefaultUserName", txt_auto_login_username.Text); sub_key0.SetValue("DefaultPassword", txt_auto_login_password.Text); sub_key0.SetValue("DontDisplayLastUserName", "1"); sub_key0.SetValue("IgnoreShiftOverride", "1"); foreach (string vname in sub_key0.GetValueNames()) { if (vname == "LegalNoticeCaption") { sub_key0.DeleteValue("LegalNoticeCaption"); } if (vname == "LegalNoticeText") { sub_key0.DeleteValue("LegalNoticeText"); } if (vname == "ForceAutoLogon") { sub_key0.DeleteValue("ForceAutoLogon"); } } } else { foreach (string vname in sub_key0.GetValueNames()) { if (vname == "AutoAdminLogon") { sub_key0.DeleteValue("AutoAdminLogon"); } if (vname == "DefaultDomainName") { sub_key0.DeleteValue("DefaultDomainName"); } if (vname == "DefaultUserName") { sub_key0.DeleteValue("DefaultUserName"); } if (vname == "DefaultPassword") { sub_key0.DeleteValue("DefaultPassword"); } if (vname == "DontDisplayLastUserName") { sub_key0.DeleteValue("DontDisplayLastUserName"); } if (vname == "IgnoreShiftOverride") { sub_key0.DeleteValue("IgnoreShiftOverride"); } if (vname == "LegalNoticeCaption") { sub_key0.DeleteValue("LegalNoticeCaption"); } if (vname == "LegalNoticeText") { sub_key0.DeleteValue("LegalNoticeText"); } if (vname == "ForceAutoLogon") { sub_key0.DeleteValue("ForceAutoLogon"); } } } sub_key0.Close(); //程序隨PC啟動 RegistryKey sub_key1 = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); string Path_str = System.Windows.Forms.Application.ExecutablePath; if (this.checkBox_auto_start.Checked == true) { sub_key1.SetValue("點晴MIS信息通后臺服務(wù)程序", Path_str); } else { sub_key1.DeleteValue("點晴MIS信息通后臺服務(wù)程序"); } sub_key1.Close(); localKey.Close();
該文章在 2021/2/18 22:39:00 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |