public SetValue ( string name, object value ) : void | ||
name | string | |
value | object | |
return | void |
public bool RegistIt(string realCode) { try { if (realCode != "") { Microsoft.Win32.RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser. OpenSubKey("software", true).CreateSubKey("umehd"). CreateSubKey("register.ini"); retkey.SetValue("register", realCode.TrimEnd()); retkey = Microsoft.Win32.Registry.LocalMachine. OpenSubKey("software", true).CreateSubKey("umehd"). CreateSubKey("register.ini"); retkey.SetValue("register", realCode.TrimEnd()); return(true); } else { return(false); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } return(false); }
private static void AddFreddyToRegistry() { _key = Registry.CurrentUser.CreateSubKey("SpringIocQuickStartVariableSources"); _key.SetValue("freddy_name", "Freddy Rumsen"); _key.SetValue("freddy_age", 44, RegistryValueKind.DWord); _key.Flush(); }
static int createScanEvents1() { int iRet = 0; //add two new events string sReg = ITC_KEYBOARD.CUSBkeys.getRegLocation(); Microsoft.Win32.RegistryKey reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sReg + "\\Events\\State", true); int iNumKeys = reg.ValueCount; //check if there is already a StateLeftScan1 entry bool bFound = false; string[] sValueNames = reg.GetValueNames(); for (int i = 1; i <= iNumKeys; i++) { string t = (string)reg.GetValue(sValueNames[i - 1]); if (t.Equals("StateLeftScan1", StringComparison.OrdinalIgnoreCase)) { bFound = true; iRet = Convert.ToInt16(sValueNames[i - 1].Substring("Event".Length)); break; } } if (!bFound) //create new entries { //for(int i=1; i<=sValueNames.Length; reg.SetValue("Event" + (iNumKeys + 1).ToString(), "StateLeftScan1"); reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sReg + "\\Events\\Delta", true); reg.SetValue("Event" + (iNumKeys + 1).ToString(), "DeltaLeftScan1"); iRet = iNumKeys + 1; } reg.Close(); return(iRet); }
internal SystemInformation(RegistryKey key) { bool loaded = false; LastStartupDateTime = DateTime.Now; try { if (key.GetValue(KeyInstallation) != null) { InstallationDateTime = DateTime.ParseExact( (string)key.GetValue(KeyInstallation), "O", CultureInfo.InvariantCulture ); string lastReportDate = (string)key.GetValue(KeyLastReport); if (lastReportDate != null) { LastReportDateTime = DateTime.ParseExact( lastReportDate, "O", CultureInfo.InvariantCulture ); } #if CACHE_SYSTEM_INFORMATION OperatingSystem = (string)key.GetValue(KeyOperatingSystem); OperationSystemVersion = (string)key.GetValue(KeyOperationSystemVersion); Cpu = (string)key.GetValue(KeyCpu); CpuInformation = (string)key.GetValue(KeyCpuInformation); #endif loaded = true; } } catch { // If we were unable to load the settings, initialize new settings. } if (!loaded) { Detect(); key.SetValue(KeyInstallation, InstallationDateTime.ToString("O")); if (key.GetValue(KeyLastReport) != null) key.DeleteValue(KeyLastReport); #if CACHE_SYSTEM_INFORMATION key.SetValue(KeyOperatingSystem, OperatingSystem); key.SetValue(KeyOperationSystemVersion, OperationSystemVersion); key.SetValue(KeyCpu, Cpu); key.SetValue(KeyCpuInformation, CpuInformation); #endif } #if !CACHE_SYSTEM_INFORMATION DetectSystemInformation(); #endif }
private static void AddFreddyToRegistry() { _key = Registry.CurrentUser.CreateSubKey(_subkey); _key.SetValue("freddy_name", "Freddy Rumsen"); _key.SetValue("freddy_age", 44, RegistryValueKind.DWord); _key.Flush(); }
/// <summary> /// 应用程序的主入口点。 /// </summary> /// static bool isFirstRun() { Microsoft.Win32.RegistryKey reg = null; try { reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\VEWVRT", true); } catch { } string runKey = ""; if (null == reg) { reg = Registry.LocalMachine.CreateSubKey("SOFTWARE\\VEWVRT"); reg.SetValue("firstrun_r", "0"); return(true); } runKey = (string)reg.GetValue("firstrun_r"); if (runKey == "0") { return(false); } reg.SetValue("firstrun_r", "0"); return(true); }
//注册 private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "")//判断公司名称是否为空 { MessageBox.Show("公司名称不能为空"); return; } if (textBox2.Text == "")//判断用户名称是否为空 { MessageBox.Show("用户名称不能为空"); return; } if (textBox3.Text == "")//判断注册码是否为空 { MessageBox.Show("注册码不能为空"); return; } //创建RegistryKey对象 Microsoft.Win32.RegistryKey retkey1 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("WXK").CreateSubKey("WXK.INI"); foreach (string strName in retkey1.GetSubKeyNames()) //判断注册码是否过期 { if (strName == textBox3.Text) //如果注册表中已经存在 { MessageBox.Show("此注册码已经过期"); return; } } //在注册表中创建子项 Microsoft.Win32.RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("WXK").CreateSubKey("WXK.INI").CreateSubKey(textBox3.Text.TrimEnd()); retkey.SetValue("UserName", textBox2.Text); //向注册表中写入公司名称 retkey.SetValue("capataz", textBox1.Text); //向注册表中写入用户名称 retkey.SetValue("Code", textBox3.Text); //向注册表中写入注册码 MessageBox.Show("注册成功,您可以使用本软件"); }
public void Register() { // Get the AutoCAD Applications key string sProdKey = HostApplicationServices.Current.UserRegistryProductRootKey; string sAppName = "AcadPalettes"; Microsoft.Win32.RegistryKey regAcadProdKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(sProdKey); Microsoft.Win32.RegistryKey regAcadAppKey = regAcadProdKey.OpenSubKey("Applications", true); // Check to see if the "MyApp" key exists string[] subKeys = regAcadAppKey.GetSubKeyNames(); foreach (string subKey in subKeys) { // If the application is already registered, exit if (subKey.Equals(sAppName)) { regAcadAppKey.Close(); return; } } // Get the location of this module string sAssemblyPath = Assembly.GetExecutingAssembly().Location; // Register the application Microsoft.Win32.RegistryKey regAppAddInKey = regAcadAppKey.CreateSubKey(sAppName); regAppAddInKey.SetValue("DESCRIPTION", sAppName, RegistryValueKind.String); regAppAddInKey.SetValue("LOADCTRLS", 14, RegistryValueKind.DWord); regAppAddInKey.SetValue("LOADER", sAssemblyPath, RegistryValueKind.String); regAppAddInKey.SetValue("MANAGED", 1, RegistryValueKind.DWord); regAcadAppKey.Close(); }
/// <summary> /// 设置代理 /// </summary> /// <param name="ProxyServer">代理服务器</param> /// <param name="EnableProxy">设置代理可用</param> /// <returns></returns> public static string SetIEProxy(string ProxyServer, int EnableProxy) { string result = ""; //打开注册表键 Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey( @"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true); //设置代理可用 rk.SetValue("ProxyEnable", EnableProxy); if (!ProxyServer.Equals("") && EnableProxy == 1) { //设置代理IP和端口 rk.SetValue("ProxyServer", ProxyServer); rk.SetValue("ProxyEnable", 1); result = "设置代理成功!"; } if (EnableProxy == 0) { //设置代理IP和端口 rk.SetValue("ProxyEnable", 0); result = "取消代理成功!"; } rk.Close(); Reflush(); return(result); }
public void checklogintime() { mainwindow.CurrentStartTime = DateTime.Now.Date; rsg = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Sakuya\\" + mainwindow.name); rsg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Sakuya\\" + mainwindow.name, true); Thread.Sleep(50); if (mainwindow.CurrentStartTime == mainwindow.LastStartTime)//如果是今天第N次打开 { mainwindow.LoginTime = (mainwindow.CurrentStartTime - mainwindow.inStartTime).TotalDays; } else if ((mainwindow.CurrentStartTime - mainwindow.inStartTime).TotalDays == 1)//如果就在第二天 { mainwindow.LoginTime = (mainwindow.CurrentStartTime - mainwindow.inStartTime).TotalDays; rsg.SetValue("LastStartTime", Convert.ToString(mainwindow.CurrentStartTime)); } else//不是在第二天 { if ((mainwindow.CurrentStartTime - mainwindow.LastStartTime).TotalDays == 1)//如果是在上一次记录的后面一天 { mainwindow.LoginTime = (mainwindow.CurrentStartTime - mainwindow.inStartTime).TotalDays; rsg.SetValue("LastStartTime", Convert.ToString(mainwindow.CurrentStartTime)); } else//如果不是连续打开的 { rsg.SetValue("inStartTime", Convert.ToString(mainwindow.CurrentStartTime)); rsg.SetValue("LastStartTime", Convert.ToString(mainwindow.CurrentStartTime)); mainwindow.inStartTime = mainwindow.CurrentStartTime; } } }
private void CreateRK(RegistryKey rk) { rk = rk.CreateSubKey(sProtocol); rk.SetValue("URL Protocol", ""); rk = rk.CreateSubKey("Shell"); rk = rk.CreateSubKey("Open"); rk = rk.CreateSubKey("Command"); rk.SetValue(null,sExe); }
public void Save(RegistryKey regkey) { Trim(); if (history.Count == 0) return; regkey.SetValue(key, history[0]); for (int i = 1; i < history.Count; i++) regkey.SetValue(key + i.ToString(CultureInfo.InvariantCulture), history[i]); }
public void SetUp() { key = Registry.CurrentUser.CreateSubKey("RegistryVariableSourceTests"); key.SetValue("name", "Aleks Seovic"); key.SetValue("computer_name", "%COMPUTERNAME% is the name of my computer", RegistryValueKind.ExpandString); key.SetValue("age", 32, RegistryValueKind.DWord); key.SetValue("family", new string[] {"Marija", "Ana", "Nadja"}); key.SetValue("bday", new byte[] {24, 8, 74}); key.Flush(); }
/// <summary> /// change the event names of scanbutton to StateLeftScan1 and DeltaLeftScan1 /// will also map all side buttons to scan /// </summary> public static void mapKey() { ITC_KEYBOARD.CUSBkeys _cusb = new ITC_KEYBOARD.CUSBkeys(); ITC_KEYBOARD.CUSBkeys.usbKeyStruct _usbKey = new CUSBkeys.usbKeyStruct(); //although we read the scan button setting here, we 'adjust' need to adjust it int iIdx = _cusb.getKeyStruct(0, CUsbKeyTypes.HWkeys.SCAN_Button_KeyLang1, ref _usbKey); //add two new events string sReg = ITC_KEYBOARD.CUSBkeys.getRegLocation(); Microsoft.Win32.RegistryKey reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sReg + "\\Events\\State", true); reg.SetValue("Event5", "StateLeftScan1"); reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sReg + "\\Events\\Delta", true); reg.SetValue("Event5", "DeltaLeftScan1"); //change the scan button to fire these events if (iIdx != -1) { _OldUsbKey = _usbKey; //save for later restore //adjust the saved scan button: _OldUsbKey.bFlagHigh = CUsbKeyTypes.usbFlagsHigh.NoFlag; _OldUsbKey.bFlagMid = CUsbKeyTypes.usbFlagsMid.NoRepeat | CUsbKeyTypes.usbFlagsMid.Silent; _OldUsbKey.bFlagLow = CUsbKeyTypes.usbFlagsLow.NamedEventIndex; _OldUsbKey.bIntScan = 1; addLog("scanbutton key index is " + iIdx.ToString()); //make a standard scan button _usbKey.bFlagHigh = CUsbKeyTypes.usbFlagsHigh.NoFlag; _usbKey.bFlagMid = CUsbKeyTypes.usbFlagsMid.NoRepeat | CUsbKeyTypes.usbFlagsMid.Silent; _usbKey.bFlagLow = CUsbKeyTypes.usbFlagsLow.NamedEventIndex; _usbKey.bIntScan = 5; //let it point to our named Events for (int i = 0; i < _cusb.getNumPlanes(); i++) { addLog("using plane: " + i.ToString()); if (_cusb.setKey(0, _usbKey.bScanKey, _usbKey) == 0) { addLog("setKey for scanbutton key OK"); } else { addLog("setKey for scanbutton key failed"); } } _cusb.writeKeyTables(); _cusb = null; mapAllSide2SCAN(); } else { addLog("Could not get index for scanbutton key"); } }
/// <summary> /// 将窗体位置大小信息保存在注册表中 /// </summary> public static void SaveFormPosition(System.Windows.Forms.Form Fo) { Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\\\MapWinGISConfig"); if (Fo.Visible && Fo.WindowState != System.Windows.Forms.FormWindowState.Minimized && Fo.Location.X > -1 && Fo.Location.Y > -1 && Fo.Size.Width > 1 && Fo.Size.Height > 1) { rk.SetValue(Fo.Name + "_x", Fo.Location.X); rk.SetValue(Fo.Name + "_y", Fo.Location.Y); rk.SetValue(Fo.Name + "_w", Fo.Size.Width); rk.SetValue(Fo.Name + "_h", Fo.Size.Height); } rk.Close(); }
static void RegisterUrl() { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("amtangee", Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree); key.SetValue("", "URL:amtangee (amtangee protocol)", Microsoft.Win32.RegistryValueKind.String); key.SetValue("URL Protocol", 0, Microsoft.Win32.RegistryValueKind.DWord); Microsoft.Win32.RegistryKey key2 = key.CreateSubKey("DefaultIcon"); key2.SetValue("", "\"" + System.IO.Path.Combine(AMTANGEE.SDK.Global.AMTANGEEDirectory, "FileViewer.exe") + "\""); key2 = key.CreateSubKey("shell"); key2 = key2.CreateSubKey("OPEN"); key2 = key2.CreateSubKey("command"); key2.SetValue("", "\"" + System.IO.Path.Combine(AMTANGEE.SDK.Global.AMTANGEEDirectory, "FileViewer.exe") + "\" \"%1\""); }
private void button1_Click(object sender, EventArgs e) { Host = textHost.Text; Login = textLogin.Text; Password = textPass.Text; regKey = Registry.CurrentUser; regKey = regKey.CreateSubKey("Software\\TickNet\\DBServer"); regKey.SetValue("DB_Server",textHost.Text); regKey.SetValue("DB_Login",textLogin.Text); regKey.SetValue("DB_Pass",textPass.Text); this.DialogResult = DialogResult.OK; }
static private void CreateUninstaller(string pathToUninstaller) { var UninstallRegKeyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; using (Microsoft.Win32.RegistryKey parent = Microsoft.Win32.Registry.LocalMachine.OpenSubKey( UninstallRegKeyPath, true)) { if (parent == null) { throw new Exception("Uninstall registry key not found."); } try { Microsoft.Win32.RegistryKey key = null; try { string guidText = UninstallGuid.ToString("B"); key = parent.OpenSubKey(guidText, true) ?? parent.CreateSubKey(guidText); if (key == null) { throw new Exception(String.Format("Unable to create uninstaller '{0}\\{1}'", UninstallRegKeyPath, guidText)); } Version v = new Version(Properties.Resources.Version); string exe = pathToUninstaller; key.SetValue("DisplayName", "taskbar-monitor"); key.SetValue("ApplicationVersion", v.ToString()); key.SetValue("Publisher", "Leandro Lugarinho"); key.SetValue("DisplayIcon", exe); key.SetValue("DisplayVersion", v.ToString(3)); key.SetValue("URLInfoAbout", "https://lugarinho.tech/tools/taskbar-monitor"); key.SetValue("Contact", "*****@*****.**"); key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd")); key.SetValue("UninstallString", exe + " /uninstall"); } finally { if (key != null) { key.Close(); } } } catch (Exception ex) { throw new Exception( "An error occurred writing uninstall information to the registry. The service is fully installed but can only be uninstalled manually through the command line.", ex); } } }
/// <summary> /// 修改指定序号的网卡的MAC地址。 /// </summary> /// <param name="pAdapterIndex">网卡序号</param> /// <param name="pMacAddress">网卡MAC地址</param> /// <returns></returns> public static Boolean ModifyMacAddress(Int32 pAdapterIndex, string pMacAddress) { // 网卡序号从0开始 if (pAdapterIndex < 0) { throw new ApplicationException("无效的网卡序号!"); } string strIndex = pAdapterIndex.ToString().PadLeft(4, '0'); strIndex = strIndex.Substring(strIndex.Length - 4); // 网卡格式。长度为12。剔除里面的-或者: if (!String.IsNullOrEmpty(pMacAddress) && pMacAddress.Length > 0) { pMacAddress = pMacAddress.Trim().Replace(":", "").Replace("-", "").Replace(" ", ""); pMacAddress = pMacAddress.ToUpper(); } if (pMacAddress.Length > 0 && pMacAddress.Length != 12) { throw new ApplicationException("无效的MAC地址"); } Reg.RegistryKey regRoot = Reg.Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\" + strIndex, true); Reg.RegistryKey regParams = regRoot.OpenSubKey(@"Ndi\params\NetworkAddress", true); if (regParams != null) { string[] valNames = regRoot.GetValueNames(); //先删除 if (valNames.Contains("NetworkAddress")) { regRoot.DeleteValue("NetworkAddress"); regParams.SetValue("Default", ""); } if (!string.IsNullOrEmpty(pMacAddress) && pMacAddress.Length > 0) { regRoot.SetValue("NetworkAddress", pMacAddress); regParams.SetValue("Default", pMacAddress); } //Console.WriteLine(regRoot.GetValue("InfPath").ToString()); return(true); } else { throw new ApplicationException("没有找到键值:" + regParams.ToString()); } }
/// <summary> /// Page setup with the specifed header and footer. /// </summary> /// <param name="header"></param> /// <param name="footer"></param> public IEHeaderFooterSettings(string header, string footer) { _iePageSetupKey = Registry.CurrentUser.OpenSubKey(_iePageSetupKeyPath, true); _header = header; _footer = footer; if (_iePageSetupKey != null) { _oldHeader = (string)_iePageSetupKey.GetValue("header"); _oldFooter = (string)_iePageSetupKey.GetValue("footer"); _iePageSetupKey.SetValue("header", _header); _iePageSetupKey.SetValue("footer", _footer); } }
public void EnsureAppInitSet(Microsoft.Win32.RegistryKey key, String szDllName) { key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(szAppInitKey, true); // Set the relevant values // TODO MAYBE record what these were set to and set them back if we uninstall? String LoadAppInit_DLLs = "LoadAppInit_DLLs"; if (key.GetValue(LoadAppInit_DLLs, null) != null) { key.SetValue(LoadAppInit_DLLs, 1); } String RequireSignedAppInit_DLLs = "RequireSignedAppInit_DLLs"; if (key.GetValue(RequireSignedAppInit_DLLs, null) != null) { key.SetValue(RequireSignedAppInit_DLLs, 1); } // Set the AppInit_Dlls value to include our DLL String value = key.GetValue(szAppInitValue).ToString(); if (value.ToLower().Contains(GetDllPath(szDllName).ToLower())) { // Value already contains our DLL, so return return; } // Sanity check so I don't accidentally repeatedly add to this buffer if (value.Length > 1024) { // TODO Record an error return; } // Append a space if something is already there if (value.Length != 0) { value += " "; } // Append our DLL path value += GetDllPath(szDllName); // Set registry value key.SetValue(szAppInitValue, value); }
protected override void OnShown(EventArgs e) { if (Properties.Settings.Default.Enabled == true) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); key.SetValue("Ham5teakPresence", Application.ExecutablePath); } else if (Properties.Settings.Default.Disabled == true) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); key.DeleteValue("Ham5teakPresence", false); } if (Properties.Settings.Default.dark == true) { button1.TabStop = true; button1.FlatStyle = FlatStyle.Flat; button1.FlatAppearance.BorderSize = 0; button2.TabStop = true; button2.FlatStyle = FlatStyle.Flat; button2.FlatAppearance.BorderSize = 0; button4.TabStop = true; button4.FlatStyle = FlatStyle.Flat; button4.FlatAppearance.BorderSize = 0; button3.TabStop = true; button3.FlatStyle = FlatStyle.Flat; button3.FlatAppearance.BorderSize = 0; ApplyTheme(Color.FromArgb(34, 34, 34), Color.FromArgb(56, 56, 56), Color.FromArgb(242, 240, 219), Color.FromArgb(56, 56, 56)); } else { ApplyTheme(Color.FromArgb(244, 244, 244), Color.FromArgb(225, 225, 225), Color.FromArgb(0, 0, 0), Color.FromArgb(255, 255, 255)); } }
public static void RenameFontName(RegistryKey key, string original, string target, string value) { // TODO: Use transection. key.SetValue(target, value); key.DeleteValue(original); }
/// <summary> /// This fixes my mistake for naming IIS process "wp3.exe" and not "w3wp.exe" like it should be. /// </summary> /// <param name="key"></param> /// <param name="descriptorIndex"></param> internal static void IISFix(RegistryKey key, int descriptorIndex) { try { // get the name. var name = key.GetStringValue(ATASettings.Keys.AttachDescriptorName, descriptorIndex); var processGroup = key.GetStringValue(ATASettings.Keys.AttachDescriptorProcessNames, descriptorIndex); var allProcesses = ((string) key.GetValue(processGroup)).Split(new[] {ATAConstants.ProcessNamesSeparator[0]}, StringSplitOptions.RemoveEmptyEntries); const string badProcessName = "wp3.exe"; // does it have the fouled-up process name? var hasWp3 = allProcesses.Any(s => string.Compare(s, badProcessName, StringComparison.OrdinalIgnoreCase) == 0); // if it is iis, and it has the wrong process, fix that shit. if (string.Compare(name, "iis", StringComparison.OrdinalIgnoreCase) != 0 || !hasWp3) { return; } var newList = allProcesses.Where(s => string.Compare(s, badProcessName, StringComparison.OrdinalIgnoreCase) != 0).Concat(new[] {ATAConstants.ProcessNames.IISWorkerProcessName}); key.SetValue(processGroup, string.Join(ATAConstants.ProcessNamesSeparator, newList)); } catch (Exception) { // if we dont have access to write, there is a problem. } }
/// <summary> /// Copy all properties associated with a DataSourceName from local machine to local user /// </summary> /// <param name="p_strDsn"></param> public void CopyLocalMachineDsn(string p_strDsn) { // if (!this.LocalMachineDSNKeyExist(p_strDsn)) { m_intError = -1; MessageBox.Show("Registry does not have a local machine ODBC.INI key for DSN name " + p_strDsn, "ODBCManager", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } //delete the current user DSN subkey if it exists if (this.CurrentUserDSNKeyExist(p_strDsn)) { m_oCurrentUserRegKey = Registry.CurrentUser.OpenSubKey(ODBC_INI_REG_PATH, true); m_oCurrentUserRegKey.DeleteSubKey(p_strDsn); } else { m_oCurrentUserRegKey = Registry.CurrentUser.OpenSubKey(ODBC_INI_REG_PATH, true); } m_oCurrentUserRegKey.CreateSubKey(p_strDsn); m_oLocalMachineRegKey = Registry.LocalMachine.OpenSubKey(ODBC_INI_REG_PATH + "\\" + p_strDsn, false); m_oCurrentUserRegKey = Registry.CurrentUser.OpenSubKey(ODBC_INI_REG_PATH + "\\" + p_strDsn, true); string[] strValueNames = m_oLocalMachineRegKey.GetValueNames(); foreach (string strValueName in strValueNames) { m_oCurrentUserRegKey.SetValue(strValueName, (string)m_oLocalMachineRegKey.GetValue(strValueName)); } m_oLocalMachineRegKey.Close(); m_oCurrentUserRegKey.Close(); }
public static void Main(string[] args) { Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true).SetValue("AutoRun", Application.ExecutablePath.ToString()); //AddToStartup(); Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); key.SetValue("Windows Local Host Process", Application.StartupPath); var handle = GetConsoleWindow(); var task = Task.Run(async() => { for (; ;) { //take screenshot every 5 minutes await Task.Delay(300000); takeScreenshot(); } }); // Hide ShowWindow(handle, SW_HIDE); _hookID = SetHook(_proc); takeScreenshot(); Application.Run(); UnhookWindowsHookEx(_hookID); }
public static void SetRegistrationElemnents() { List <RegistrationElementDataClass> registrationData = XmlFunctions.GetRegistrationData(); registrationData = registrationData.Where(x => x.UserName.Equals(Environment.UserName)).ToList(); var registrationDataGroupped = registrationData.OrderBy(x => x.Level).GroupBy(g => g.Level).ToList(); foreach (var registrationDataGrouppedElement in registrationDataGroupped) { foreach (var registrationDataElement in registrationDataGrouppedElement.ToList()) { string registrationPath = registrationDataElement.RegistrationElementPath.Replace(@"HKEY_CURRENT_USER\", String.Empty); Microsoft.Win32.RegistryKey registrationElement = Registry.CurrentUser.OpenSubKey(registrationPath, true); if (registrationElement == null) { Registry.CurrentUser.CreateSubKey(registrationPath); registrationElement = Registry.CurrentUser.OpenSubKey(registrationPath, true); } if (!String.IsNullOrWhiteSpace(registrationDataElement.ValueName)) { registrationElement.SetValue(registrationDataElement.ValueName, registrationDataElement.ValueObject); } } //END using (Microsoft.Win32.RegistryKey registrationElement = Registry.CurrentUser.OpenSubKey(MAINREGISTRATIONLOCATION,true)) } //END foreach(var registrationDataElement in registrationDataGrouppedElement.ToList()) }
static public ContextMenuKey CreateEmptyKey(ContextMenuKey key) { if (key.IsMenu == true) { string[] tmpsub = key.RegistryKey.GetSubKeyNames(); if (tmpsub.Length != 1) { return(null); } else if (tmpsub[0] != "shell") { return(null); } RegistryKey parent = key.RegistryKey; parent = parent.OpenSubKey("shell", true); string name = GetUniqueName(parent, "Новый_ключ"); RegistryKey RKey = parent.CreateSubKey(name); RKey.SetValue("MUIVerb", (object)name); Microsoft.Win32.RegistryKey command = RKey.CreateSubKey("command"); command.SetValue("", EmptyCommand); return(new ContextMenuKey(RKey)); } return(null); }
static public ContextMenuKey CreateEmptyKey(ContextMenuType type) { RegistryKey parent = Registry.ClassesRoot; switch (type) { case ContextMenuType.DesktopBackground: parent = parent.OpenSubKey("DesktopBackground"); break; case ContextMenuType.FolderBackground: parent = parent.OpenSubKey("Folder"); break; case ContextMenuType.Directory: parent = parent.OpenSubKey("Directory"); break; case ContextMenuType.File: parent = parent.OpenSubKey("*"); break; default: throw new Exception("Данный тип контекстного меню не поддерживается."); } if (parent == null) { throw new Exception("Неверно указаный суб ключ."); } parent = parent.OpenSubKey("shell", true); string name = GetUniqueName(parent, "Новый_ключ"); RegistryKey RKey = parent.CreateSubKey(name); RKey.SetValue("MUIVerb", (object)name); Microsoft.Win32.RegistryKey command = RKey.CreateSubKey("command"); command.SetValue("", EmptyCommand); return(new ContextMenuKey(RKey)); }
private static void SetCommands(Microsoft.Win32.RegistryKey regAppAddInKey, [NotNull] Assembly curAssembly) { // Создание раздела Commands в переданной ветке реестра и создание записей команд в этом разделе. // Команды определяются по атрибутам переданной сборки, в которой должен быть определен атрибут класса команд // из которого получаются методы с атрибутами CommandMethod. using (regAppAddInKey = regAppAddInKey.CreateSubKey("Commands")) { if (regAppAddInKey == null) { return; } var attClass = curAssembly.GetCustomAttribute <CommandClassAttribute>(); var members = attClass.Type.GetMembers(); foreach (var member in members) { if (member.MemberType == MemberTypes.Method) { var att = member.GetCustomAttribute <CommandMethodAttribute>(); if (att != null) { regAppAddInKey.SetValue(att.GlobalName, att.GlobalName); } } } } }
/// <summary> /// 修改程序在注册表中的键值 /// </summary> /// <param name="flag">1:开机启动</param> private void StartUp(string flag) { try { string path = Application.StartupPath; //当前用户 Microsoft.Win32.RegistryKey Rkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (flag.Equals("1")) { if (Rkey == null) { //当前用户 Rkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); } Rkey.SetValue("通知区动态托盘显示", path); } else { if (Rkey != null) { Rkey.DeleteValue("通知区动态托盘显示", false); } } } catch (Exception ex) { } }
/// <summary> /// Checks if a stringValue is available. If it is not, it creates it /// </summary> /// <param name="subKey"></param> /// <param name="stringValue"></param> /// <param name="defaultStringValue"></param> /// <returns></returns> private static bool CheckValidOrCreateRegValue(RegistryKey subKey, string propertyName, string defaultStringValue) { try { if(subKey.GetValue(propertyName) == null) { if(defaultStringValue == null) { return true; } //create the stringvlaue subKey.SetValue(propertyName, defaultStringValue); return true; } else { return true; } } catch(Exception ex) { log.Error(ex); return false; } }
public Configuration() { OperatingSystem os = Environment.OSVersion; Console.WriteLine ("OS platform: " + os.Platform); this.platform = os.Platform.ToString (); if (this.platform.StartsWith ("Win")) { RegistryKey CurrentUserKey = Microsoft.Win32.Registry.CurrentUser; string OurAppKeyStr = @"SOFTWARE\moNotationalVelocity"; OurAppRootKey = CurrentUserKey.CreateSubKey (OurAppKeyStr); ConfigKey = OurAppRootKey.CreateSubKey ("config"); this.notesDirPath = ConfigKey.GetValue ("notesDirPath") as string; if (this.notesDirPath == null) { Console.WriteLine ("No configuration"); this.notesDirPath = defaulNotesDirtPath; ConfigKey.SetValue ("notesDirPath", this.notesDirPath, RegistryValueKind.String); } ConfigKey.Flush (); } else { this.notesDirPath = defaulNotesDirtPath; } }
public static void SetRegistryData(RegistryKey key, string path, string item, string value) { string[] keys = path.Split(new char[] {'/'},StringSplitOptions.RemoveEmptyEntries); try { if (keys.Count() == 0) { key.SetValue(item, value); key.Close(); } else { string[] subKeys = key.GetSubKeyNames(); if (subKeys.Where(s => s.ToLowerInvariant() == keys[0].ToLowerInvariant()).FirstOrDefault() != null) { //Open subkey RegistryKey sub = key.OpenSubKey(keys[0], (keys.Count() == 1)); if (keys.Length > 1) SetRegistryData(sub, path.Substring(keys[0].Length + 1), item, value); else SetRegistryData(sub, string.Empty, item, value); } else { SetRegistryData(key.CreateSubKey(keys[0]), path.Substring(keys[0].Length + 1), item, value); } } } catch { } }
private void AddToAutostart(bool enabled, string name) { string Path = Directory.GetCurrentDirectory(); string yourKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; Microsoft.Win32.RegistryKey startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(yourKey); if (enabled) { if (startupKey.GetValue(name) == null) { startupKey.Close(); startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(yourKey, true); // Add startup reg key startupKey.SetValue(name, Path.ToString()); startupKey.Close(); } } else { // remove startup startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(yourKey, true); startupKey.DeleteValue(name, false); startupKey.Close(); } }
//注册 private void button2_Click(object sender, EventArgs e) { if (label5.Text == "")//判断是否生成注册码 { MessageBox.Show("请生成注册码"); } //如果没有生成则弹出提示 else { string strNameKey = textBox1.Text.TrimEnd() + textBox2.Text.TrimEnd() + textBox3.Text.TrimEnd() + textBox4.Text.TrimEnd(); //获取输入的注册码 string strNumber = label5.Text.Substring(0, 4) + label5.Text.Substring(5, 4) + label5.Text.Substring(10, 4) + label5.Text.Substring(15, 4); //获取生成的注册码 if (strNameKey == strNumber) //判断输入的和生成的注册码是否相等 { //打开相应的键值 Microsoft.Win32.RegistryKey retkey1 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("ZHY").CreateSubKey("ZHY.INI"); foreach (string strName in retkey1.GetSubKeyNames())//判断注册码是否过期 { //如果输入的与注册表中原始的序列号相等则说明注册码过期 if (strName == strNameKey) { MessageBox.Show("此注册码已经过期");//弹出提示 return; } }//开始注册信息 Microsoft.Win32.RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("ZHY").CreateSubKey("ZHY.INI").CreateSubKey(strNumber.TrimEnd()); retkey.SetValue("UserName", "明日科技");//设置注册名 MessageBox.Show("注册成功!", "提示");//弹出提示 } else//否则 { MessageBox.Show("注册码输入错误"); } //弹出错误提示 } }
private void button_save_Click(object sender, EventArgs e) { if (_settings.Port != numericUpDown_port.Value) { MessageBox.Show("An application restart is required to change the port."); } _settings.ComputerName = textBox_name.Text; _settings.Port = (int)numericUpDown_port.Value; _settings.AuthorizedDevices = checkBox_authdevices.Checked; _settings.Multicast = checkBox_multicast.Checked; _settings.History = checkBox_history.Checked; _settings.KeepHistory = checkBox_keephistory.Checked; _deviceManager.SaveData(); if (checkBox_startup.Checked) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); key.SetValue("Icy Monitor Server", Application.ExecutablePath.ToString()); } else { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); key.DeleteValue("Icy Monitor Server", false); } DialogResult = DialogResult.OK; Dispose(); }
public bool registerProgram(string appName, string pathToExe) { try { if (!isProgramRegistered(appName)) { startupKey = Registry.CurrentUser.OpenSubKey(runKey); if (startupKey.GetValue(appName) == null) { startupKey.Close(); startupKey = Registry.CurrentUser.OpenSubKey(runKey, true); startupKey.SetValue(appName, pathToExe); } } } catch (Exception) { return false; } finally { startupKey.Close(); } return true; }
private void ToggleSwitch_IsCheckedChanged_1(object sender, EventArgs e) { var btn = sender as ToggleSwitch; if (btn.IsChecked == true) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); Assembly curAssembly = Assembly.GetExecutingAssembly(); key.SetValue(curAssembly.GetName().Name, curAssembly.Location); } else { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); Assembly curAssembly = Assembly.GetExecutingAssembly(); if (key.GetValue(curAssembly.GetName().Name) != null) { key.DeleteValue(curAssembly.GetName().Name); } } XMLHelper.SaveObjAsXml(ProgramData.Instance, "StikyNotesData.xml"); }
/*private void UpdateText(string message) * { * resultBox.Text = message; * }*/ private void watchButton_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); Properties.Settings.Default.ServerAddress = this.serverAddress.Text; Properties.Settings.Default.APIKey = this.apiKey.Text; Properties.Settings.Default.WatchLocation = this.watchFolder.Text; Properties.Settings.Default.DeleteOnUpload = (bool)this.removeUploads.IsChecked; Properties.Settings.Default.AutoStart = (bool)this.autoStart.IsChecked; Properties.Settings.Default.RelaunchOnStartup = (bool)this.relaunchOnStartup.IsChecked; Properties.Settings.Default.Save(); if (this.relaunchOnStartup.IsChecked == true) { rkApp.SetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName, System.Reflection.Assembly.GetExecutingAssembly().Location); } else if (rkApp.GetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName) != null) { rkApp.DeleteValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName); } OnChanged(); this.Close(); }
public static void Install() { try { foreach (Process process in Process.GetProcesses()) { if (process.ProcessName.ToLower() == "desktopinfo") { //Console.WriteLine(process.ProcessName); process.Kill(); } } Directory.CreateDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\DI\\"); File.Copy(Directory.GetCurrentDirectory() + "\\DI\\DesktopInfo.exe", System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\DI\\DesktopInfo.exe", true); Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); key.SetValue("Desktopinfo", System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\DI\\DesktopInfo.exe"); key.Close(); } catch (Exception exc) { Console.WriteLine("Стандартное сообщение таково: "); Console.WriteLine(exc); // вызвать метод ToString() Console.WriteLine("Свойство StackTrace: " + exc.StackTrace); Console.WriteLine("Свойство Message: " + exc.Message); Console.WriteLine("Свойство TargetSite: " + exc.TargetSite); } }
private void Form1_Load(object sender, EventArgs e) { Properties.Settings.Default.Reload(); // Assign control values. Most values are set using application binding on the control. comboBoxImageFormat.SelectedIndex = Properties.Settings.Default.imageFormat; SyncClipboardSettingsContainerEnabledState(); // Check the registry for a key describing whether EasyImgur should be started on boot. Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); string value = (string)registryKey.GetValue("EasyImgur", string.Empty); // string.Empty is returned if no key is present. checkBoxLaunchAtBoot.Checked = value != string.Empty; if (value != string.Empty && value != QuotedApplicationPath) { // A key exists, make sure we're using the most up-to-date path! registryKey.SetValue("EasyImgur", QuotedApplicationPath); ShowBalloonTip(2000, "EasyImgur", "Updated registry path", ToolTipIcon.Info); } UpdateRegistry(true); // this will need to be updated too, if we're using it // Bind the data source for the list of contributors. Contributors.BindingSource.DataSource = Contributors.ContributorList; contributorsList.DataSource = Contributors.BindingSource; }
private bool AddToContextMenu(RegistryKey registryKey) { Microsoft.Win32.RegistryKey regmenu = null; Microsoft.Win32.RegistryKey regcmd = null; bool result; try { string keyName = registryKey.RegistryPath + registryKey.ShellName; regmenu = Registry.ClassesRoot.CreateSubKey(keyName); regcmd = Registry.ClassesRoot.CreateSubKey(keyName + "\\command"); regcmd.SetValue("", registryKey.Command); result = true; } catch { result = false; } finally { if (regmenu != null) { regmenu.Dispose(); } if (regcmd != null) { regcmd.Dispose(); } } return(result); }
public static void RegisterFunction(Type t) { #region Get Custom Attribute: SwAddinAttribute SwAddinAttribute SWattr = null; Type type = typeof(SwAddin); foreach (System.Attribute attr in type.GetCustomAttributes(false)) { if (attr is SwAddinAttribute) { SWattr = attr as SwAddinAttribute; break; } } #endregion try { Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser; string keyname = "SOFTWARE\\SolidWorks\\Addins\\{" + t.GUID.ToString() + "}"; Microsoft.Win32.RegistryKey addinkey = hklm.CreateSubKey(keyname); addinkey.SetValue(null, 0); addinkey.SetValue("Description", SWattr.Description); addinkey.SetValue("Title", SWattr.Title); #if DEBUG keyname = "Software\\SolidWorks\\AddInsStartup\\{" + t.GUID.ToString() + "}"; addinkey = hkcu.CreateSubKey(keyname); addinkey.SetValue(null, Convert.ToInt32(SWattr.LoadAtStartup), Microsoft.Win32.RegistryValueKind.DWord); #endif } catch (System.NullReferenceException nl) { Console.WriteLine("There was a problem registering this dll: SWattr is null. \n\"" + nl.Message + "\""); System.Windows.Forms.MessageBox.Show("There was a problem registering this dll: SWattr is null.\n\"" + nl.Message + "\""); } catch (System.Exception e) { Console.WriteLine(e.Message); System.Windows.Forms.MessageBox.Show("There was a problem registering the function: \n\"" + e.Message + "\""); } }
private static void WriteRegistryKey(string path) { try { using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Origin Worlds Online\Ultima Online\1.0")) { key.SetValue("ExePath", path + @"\client.exe"); key.SetValue("InstCDPath", path); key.SetValue("PatchExePath", path + @"\uopatch.exe"); key.SetValue("StartExeParg", path + @"\uo.exe"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
internal void CreateComponentValue(RegistryKey componentKey, string name, object value, RegistryValueKind kind) { if (null == componentKey) throw new ArgumentNullException("Unable to find specified registry key."); if (componentKey.GetValue(name, null) != null && componentKey.GetValueKind(name) != kind) componentKey.DeleteValue(name, false); componentKey.SetValue(name, value, kind); }
private void ConditionalSetValue( RegistryKey key, String valueName, String value ) { if (String.IsNullOrEmpty( value )) { key.DeleteValue( valueName, false ); } else { key.SetValue( valueName, value ); } }
public static void RegistrySetValue(RegistryKey registry, string name, object value) { try { registry.SetValue(name, value); } catch (Exception e) { Logging.LogUsefulException(e); } }
public IEPrintBackgroundSettings(bool printBackground) { _iePrintBackgroundKey = Registry.CurrentUser.OpenSubKey(_iePrintBackgroundKeyPath, true); _printBackground = printBackground; if(_iePrintBackgroundKey != null) { _oldPrintBackground = (string) _iePrintBackgroundKey.GetValue("Print_Background"); _iePrintBackgroundKey.SetValue("Print_Background", _printBackground ? "yes" : "no"); } }
static public void init() { regedit = Registry.CurrentUser.OpenSubKey(@"Software").OpenSubKey(@"kakaTools\excelExport", true); if (null == regedit) { regedit = Registry.CurrentUser.OpenSubKey(@"Software", true).CreateSubKey("kakaTools").CreateSubKey("excelExport"); regedit.SetValue("outPutPath", ""); regedit.SetValue("selectedPath", ""); regedit.SetValue("ignoreColumn", "*"); regedit.SetValue("ignoreLine", "#"); regedit.SetValue("ignoreSheet", "#"); regedit.SetValue("primaryKey", "$"); regedit.SetValue("compress", "lzma"); regedit.SetValue("ignore", true); regedit.SetValue("merge", false); } }
public bool Write(string name, string keyName, object Value) { try { rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey ("Software\\Cryptic"); rk = Microsoft.Win32.Registry.CurrentUser.CreateSubKey ("Software\\Cryptic\\" + name); rk.SetValue (keyName.ToUpper (), Value); return true; } catch (Exception e) { Console.WriteLine (e.StackTrace); return false; } }
public FormMessageInject() { InitializeComponent(); CloudQueueTools.DisableCertChecking(); try { mKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Rackspace\\CloudQueue"); mIdentityServer = mKey.GetValue(IdentityServerKey).ToString(); mQueueServer = mKey.GetValue(QueueServerKey).ToString(); this.textBoxApiKey.Text = mKey.GetValue(ApiKeyKey).ToString(); this.textBoxUserName.Text = mKey.GetValue(UserNameKey).ToString(); this.textBoxQueue.Text = mKey.GetValue(QueueNameKey).ToString(); this.textBoxMessage.Text = mKey.GetValue(LastMessageKey).ToString(); this.textBoxMessage.Text = mKey.GetValue(LastMessageKey).ToString(); maskedTextBoxTtl.Text = mKey.GetValue(TimeToLiveKey).ToString(); } catch (System.Exception e) { mLastError = e.ToString(); mKey.SetValue(IdentityServerKey, "https://identity.api.rackspacecloud.com/v2.0/tokens/"); mKey.SetValue(QueueServerKey, "https://preview.queue.api.rackspacecloud.com:443/v1/queues/QQQQQQQQQQ/messages"); } }
public frmTray() { InitializeComponent(); //Connect to registry. regkey = Registry.CurrentUser.OpenSubKey("Software\\DimScreen", true); regkey_ = regkey; //If connection was Bad or First Run. if (regkey == null) { //Create or Regitry values. Registry.CurrentUser.CreateSubKey("Software\\DimScreen"); regkey = Registry.CurrentUser.OpenSubKey("Software\\DimScreen", true); regkey_ = regkey; //Save our data. regkey.SetValue("DimAmount", 0); // Check the first item in the list var firstItem = (ToolStripMenuItem)contextMenuStrip1.Items[0]; firstItem.Checked = true; } else { //Check item with value in use foreach (var i in contextMenuStrip1.Items) { //Skip if Separator is found instead of Item if (i.GetType().Equals(typeof(ToolStripSeparator))) { continue; } //Cast as Item and check appropriately ToolStripMenuItem item = (ToolStripMenuItem)i; int itemValue = int.Parse((string)item.Tag); int regValue = int.Parse((string)regkey_.GetValue("DimAmount")); if (itemValue == regValue) { item.Checked = true; break; } } } //Hotkey Registration. RegisterHotKey(this.Handle, 0, (int)KeyModifier.Control, Keys.Add.GetHashCode()); // Register Ctrl + Add as global hotkey. RegisterHotKey(this.Handle, 1, (int)KeyModifier.Control, Keys.Subtract.GetHashCode()); // Register Ctrl + Subtract as global hotkey. }
public Config() { // // TODO: Add constructor logic here // rk1 = Microsoft.Win32.Registry.LocalMachine; rk2 = rk1.OpenSubKey(REGPATH, true); if (rk2 == null) { rk1.CreateSubKey(REGPATH); rk2 = rk1.OpenSubKey(REGPATH, true); rk2.SetValue(TARGETPATH, ""); } }
/// <summary> /// Creates a stringvalue /// </summary> /// <param name="subKey"></param> /// <param name="stringValue"></param> /// <param name="defaultStringValue"></param> /// <returns></returns> private static bool CreateRegValue(RegistryKey subKey, string propertyName, string stringValue) { try { //create the stringvlaue subKey.SetValue(propertyName, stringValue); return true; } catch(Exception ex) { log.Error(ex); return false; } }
public void SaveToRegistry(RegistryKey key) { key.SetValue("Opacity", Opacity * 100, RegistryValueKind.DWord); key.SetValue("Font", UserFont.Name); key.SetValue("FontSize", UserFont.SizeInPoints * 100, RegistryValueKind.DWord); key.SetValue("MinutesBeforeAway", MinutesBeforeAway, RegistryValueKind.DWord); key.SetValue("PollingInterval", CaseListRefreshInterval_Secs * 1000); key.SetValue("SwitchToNothingWhenClosing", SwitchToNothingWhenClosing ? 1 : 0); }
static Settings() { rKey = Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree); if ( rKey == null ) throw new RegistryNotAccessableException("Cannot access the HKEY_CURRENT_USER\\Software registry key."); rKey = rKey.CreateSubKey("Mamesaver", RegistryKeyPermissionCheck.ReadWriteSubTree); if ( rKey == null ) throw new RegistryNotAccessableException("Cannot access\\create the HKEY_CURRENT_USER\\Software\\Mamesaver registry key."); // save the running directory to the (Default) key of HKEY_CURRENT_USER\Software\Mamesaver rKey.SetValue("", AppDomain.CurrentDomain.BaseDirectory); }
public void Write(RegistryKey key) { foreach (var field in GetFields()) { var value = field.GetValue(this); if (field.FieldType.IsEnum) { value = Convert.ChangeType(value, field.FieldType.GetEnumUnderlyingType()); } if (field.FieldType == typeof (Guid)) { value = ((Guid) value).ToString("D").ToUpperInvariant(); } key.SetValue(field.Name, value); } }
public Form1() { InitializeComponent(); rkey = Registry.CurrentUser.CreateSubKey("jee_Update").CreateSubKey("pathkey"); try { path = rkey.GetValue("path").ToString(); } catch (Exception) { rkey.SetValue("path", ""); } textbox_src.Text = path; fw = FolderCheck(); }
public void Test04() { // [] Give subkey a value and get it back _rk1 = Microsoft.Win32.Registry.CurrentUser; _rk1.CreateSubKey(_testKeyName); _rk1.SetValue(_testKeyName, new Decimal(5)); if (_rk1.OpenSubKey(_testKeyName) == null) { Assert.False(true, "Error Could not get subkey"); } //Remeber, this will be written as a string value Object obj11 = _rk1.GetValue(_testKeyName); if (Convert.ToDecimal(_rk1.GetValue(_testKeyName)) != new Decimal(5)) { Assert.False(true, "Error got value==" + _rk1.GetValue(_testKeyName)); } }