public CreateSubKey ( string subkey ) : Microsoft.Win32.RegistryKey | ||
subkey | string | |
return | Microsoft.Win32.RegistryKey |
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); }
static void CreateFileAssociations() { /***********************************/ /**** Key1: Create ".cy" entry ****/ /***********************************/ Microsoft.Win32.RegistryKey key1 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", true); key1.CreateSubKey("Classes"); key1 = key1.OpenSubKey("Classes", true); key1.CreateSubKey(".cy"); key1 = key1.OpenSubKey(".cy", true); key1.SetValue("", "CryptoScript"); // Set default key value key1.Close(); /*******************************************************/ /**** Key2: Create "DemoKeyValue\DefaultIcon" entry ****/ /*******************************************************/ Microsoft.Win32.RegistryKey key2 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", true); key2.CreateSubKey("Classes"); key2 = key2.OpenSubKey("Classes", true); key2.CreateSubKey("CryptoScript"); key2 = key2.OpenSubKey("CryptoScript", true); key2.CreateSubKey("DefaultIcon"); key2 = key2.OpenSubKey("DefaultIcon", true); key2.SetValue("", "\"" + @"c:\CryptoScript\icon.ico" + "\""); // Set default key value key2.Close(); /**************************************************************/ /**** Key3: Create "DemoKeyValue\shell\open\command" entry ****/ /**************************************************************/ Microsoft.Win32.RegistryKey key3 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", true); key3.CreateSubKey("Classes"); key3 = key3.OpenSubKey("Classes", true); key3.CreateSubKey("CryptoScript"); key3 = key3.OpenSubKey("CryptoScript", true); key3.CreateSubKey("shell"); key3 = key3.OpenSubKey("shell", true); key3.CreateSubKey("open"); key3 = key3.OpenSubKey("open", true); key3.CreateSubKey("command"); key3 = key3.OpenSubKey("command", true); key3.SetValue("", "\"" + @"C:\CryptoScript\CryptoScript.exe" + "\"" + " \"%1\""); // Set default key value key3.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\""); }
/// <summary> /// Store a value in registry /// </summary> /// <param name="KeyName"></param> /// <param name="value"></param> public void AddValueToRegistry(string KeyName, string value) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", true); // key.CreateSubKey(_companyName); key = key.OpenSubKey(_companyName, true); // key.CreateSubKey(_swName); key = key.OpenSubKey(_swName, true); // key.SetValue(KeyName, value); }
public static void initialize() { RegistryKey software = Registry.CurrentUser.OpenSubKey("Software", true); options = software.CreateSubKey("Changes Checker"); list = options.CreateSubKey("list"); hashes = options.CreateSubKey("hashes"); //times = options.CreateSubKey("times"); RegistryKey userMailBeep = Registry.CurrentUser.OpenSubKey("AppEvents") .OpenSubKey("Schemes").OpenSubKey("Apps").OpenSubKey(".Default") .OpenSubKey(".Default").OpenSubKey(".Current"); soundPath = userMailBeep.GetValue("").ToString(); userMailBeep.Close(); }
private bool WriteLinkReg(Microsoft.Win32.RegistryKey key) { string app = System.Reflection.Assembly.GetExecutingAssembly().Location; //Create Prog_ID in Registry so we can associate file types //TODO: Add additional subkeys to define an "Unpack" option for IROs var progid = key.CreateSubKey("7thHeaven"); if (progid == null) { return(false); } var icon = progid.CreateSubKey("DefaultIcon"); var shell = progid.CreateSubKey("shell"); var open = shell.CreateSubKey("open"); var command = open.CreateSubKey("command"); progid.SetValue(String.Empty, "7thHeaven Mod File"); icon.SetValue(String.Empty, "\"" + app + "\""); command.SetValue(String.Empty, "\"" + app + "\" /OPENIRO:\"%1\""); //Associate .iro mod files with 7H's Prog_ID- .IRO extension var iroext = key.CreateSubKey(".iro"); if (iroext == null) { return(false); } iroext.SetValue(String.Empty, "7thHeaven"); //Refresh Shell/Explorer so icon cache updates //do this now because we don't care so much about assoc. URL if it fails SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero); //Associate iros:// URL with 7H var iros = key.CreateSubKey("iros"); if (iros == null) { return(false); } icon = iros.CreateSubKey("DefaultIcon"); shell = iros.CreateSubKey("shell"); open = shell.CreateSubKey("open"); command = open.CreateSubKey("command"); iros.SetValue(String.Empty, "7H Catalog Subscription"); icon.SetValue(String.Empty, "\"" + app + "\""); command.SetValue(String.Empty, "\"" + app + "\" \"%1\""); return(true); }
public void SetQWord(RegistryKey hive, string key, string valueName, long value) { using (var subKey = hive.CreateSubKey(key)) { subKey.SetValue(valueName, value, RegistryValueKind.QWord); } }
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; } }
protected RegistryKey GetKey(RegistryKey root, string subkey, bool writeable) { RegistryKey key = root.OpenSubKey(subkey, writeable); if (key == null && writeable) key = root.CreateSubKey(subkey); return key; }
public void TestInitialize() { var counter = Interlocked.Increment(ref s_keyCount); _testKey += counter.ToString(); _rk1 = Microsoft.Win32.Registry.CurrentUser; if (_rk1.OpenSubKey(_testKey) != null) _rk1.DeleteSubKeyTree(_testKey); if (_rk1.GetValue(_testKey) != null) _rk1.DeleteValue(_testKey); //created the test key. if that failed it will cause many of the test scenarios below fail. try { _rk1 = Microsoft.Win32.Registry.CurrentUser; _rk2 = _rk1.CreateSubKey(_testKey); if (_rk2 == null) { Assert.False(true, "ERROR: Could not create test subkey, this will fail a couple of scenarios below."); } else _keyString = _rk2.ToString(); } catch (Exception e) { Assert.False(true, "ERROR: unexpected exception, " + e.ToString()); } }
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 { } }
public void SetString(RegistryKey hive, string key, string valueName, string value) { using (var subKey = hive.CreateSubKey(key)) { subKey.SetValue(valueName, value); } }
/// <summary> /// Copies recursivelly the registry data from the source to the destination key. /// </summary> /// <param name="srcKey">The source key.</param> /// <param name="srcPath">The source path.</param> /// <param name="dstKey">The destination key.</param> /// <param name="dstPath">The detination path.</param> /// <param name="progress">A delegate to the progress.</param> /// <returns><b>True</b> if the copy was successful, <b>false</b> otherwise.</returns> public static bool CopyKey(RegistryKey srcKey, string srcPath, RegistryKey dstKey, string dstPath, Action<string, string> progress = null) { // Open the source key. using (RegistryKey src = srcKey.OpenSubKey(srcPath, RegistryKeyPermissionCheck.ReadWriteSubTree)) { // If the source key is null, return. if (null == src) return false; // Create the destination key. using (RegistryKey dst = dstKey.CreateSubKey(dstPath, RegistryKeyPermissionCheck.ReadWriteSubTree)) { // If the destination key is null, return. if (null == dst) return false; // If the progress delegate is not null, update the progress. if (null != progress) progress(src.Name, dst.Name); // Copy all values. foreach (string value in src.GetValueNames()) { // Copy the values. dst.SetValue(value, src.GetValue(value), src.GetValueKind(value)); } // Perform a recursive copy of the registry keys. foreach (string subkey in src.GetSubKeyNames()) { // Copy the registry key. RegistryExtensions.CopyKey(src, subkey, dst, subkey, progress); } return true; } } }
static void initKeys() { if (mainKey != null) return; mainKey = Custom.BaseKey; // Registry.CurrentUser.CreateSubKey("SOFTWARE\\Repetier"); windowKey = mainKey.CreateSubKey("window"); }
public static int[] WindowsRegCreateKeyEx(int hKey, byte[] subKey) { Microsoft.Win32.RegistryKey resultKey = null; int error = 0; int disposition = -1; try { Microsoft.Win32.RegistryKey key = MapKey(hKey); string name = BytesToString(subKey); resultKey = key.OpenSubKey(name); disposition = 2; if (resultKey == null) { resultKey = key.CreateSubKey(name); disposition = 1; } } catch (SecurityException) { error = 5; } catch (UnauthorizedAccessException) { error = 5; } return(new int[] { AllocHandle(resultKey), error, disposition }); }
public bool Upgrade(IIndentGuide service, RegistryKey root, string subkeyName) { int version; using (var reg = root.OpenSubKey(subkeyName, false)) { version = (reg == null) ? 0 : (int)reg.GetValue("Version", IndentGuidePackage.DEFAULT_VERSION); } if (version == 0 || version == IndentGuidePackage.Version) { return false; } using (var reg = root.CreateSubKey(subkeyName)) { if (version >= 0x000C0903) { // Nothing to upgrade } else if (version == 0x000C0902) { UpgradeFrom_12_9_2(reg); } else if (version >= 0x000C0000) { // Nothing to upgrade } else if (version >= 0x000B0901) { UpgradeFrom_11_9_0(reg); } else if (version >= 0x000A0901) { UpgradeFrom_10_9_1(reg); } else { UpgradeFrom_Earlier(reg); } // Upgrading will make guides visible regardless of the // previous setting. reg.SetValue("Visible", 1); } return true; }
public static bool SetRegistryValue(RegistryKey RootKey, string szSubKey, string szItem, string value) { bool bIsSuccessful = false; try { RegistryKey registryKey = RootKey.OpenSubKey(szSubKey, true); if (registryKey == null) { registryKey = RootKey.CreateSubKey(szSubKey); } if (registryKey != null) { using (registryKey) { registryKey.SetValue(szItem, value); bIsSuccessful = true; } } } catch (UnauthorizedAccessException) { return bIsSuccessful; } return bIsSuccessful; }
/// <summary> /// Sets .dnd4e File Association to CBLoader. /// This means that the user can double-click a character file and launch CBLoader. /// </summary> public static void UpdateRegistry(bool silent = false) { // I'm not going to bother explaining File Associations. Either look it up yourself, or trust me that it works. try // Changing HKCL needs admin permissions { Microsoft.Win32.RegistryKey cuClasses = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("Classes"); var k = cuClasses.CreateSubKey(".dnd4e"); k.SetValue("", ".dnd4e"); k = k.CreateSubKey("shell"); k = k.CreateSubKey("open"); k = k.CreateSubKey("command"); k.SetValue("", "\"" + (Environment.CurrentDirectory.ToString() + "\\CBLoader.exe\" \"%1\"")); // All Users k = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(".dnd4e"); k.SetValue("", ".dnd4e"); k = k.CreateSubKey("shell"); k = k.CreateSubKey("open"); k = k.CreateSubKey("command"); k.SetValue("", "\"" + (Environment.CurrentDirectory.ToString() + "\\CBLoader.exe\" \"%1\"")); // And the cbconfig files k = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(".cbconfig"); k.SetValue("", ".cbconfig"); k = k.CreateSubKey("shell"); k = k.CreateSubKey("open"); k = k.CreateSubKey("command"); k.SetValue("", "\"" + (Environment.CurrentDirectory.ToString() + "\\CBLoader.exe\" -c \"%1\"")); } catch (UnauthorizedAccessException ua) { if (!silent) { Log.Error("There was a problem setting file associations", ua); } } }
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(); }
public static string GetRegString(Microsoft.Win32.RegistryKey hkey, string vname) { try { RegistryKey key = hkey.OpenSubKey(RazorRegPath); if (key == null) { key = hkey.CreateSubKey(RazorRegPath); if (key == null) { return(null); } } string v = key.GetValue(vname) as string; if (v == null) { return(null); } return(v.Trim()); } catch { return(null); } }
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); } } } } }
private Microsoft.Win32.RegistryKey GetAcadAppKey(bool forWrite) { string User = Environment.UserDomainName + "\\" + Environment.UserName; string RootKey = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.Current.UserRegistryProductRootKey; Microsoft.Win32.RegistryKey AcadKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(RootKey); RegistryAccessRule Role = new RegistryAccessRule(User, RegistryRights.WriteKey | RegistryRights.Delete | RegistryRights.ReadKey, AccessControlType.Allow); RegistrySecurity Rs = new RegistrySecurity(); Rs.AddAccessRule(Role); Microsoft.Win32.RegistryKey AppKey = AcadKey.OpenSubKey("Applications", forWrite); if (AppKey == null) { try { Microsoft.Win32.RegistryKey Key = AcadKey.CreateSubKey("Applications", RegistryKeyPermissionCheck.ReadWriteSubTree, Rs); return(Key); } catch (System.Exception Ex) { AcadApp.ShowAlertDialog(Ex.Message + "注册失败。详情请查看软件的帮助文档"); return(AppKey); } } else { return(AppKey); } }
public void Test04() { // [] Give subkey a value and then delete tree _rk1 = Microsoft.Win32.Registry.CurrentUser; _rk1.CreateSubKey(_testKeyName); if (_rk1.OpenSubKey(_testKeyName) == null) { Assert.False(true, "Error Could not get subkey"); } _rk1.DeleteSubKeyTree(_testKeyName); if (_rk1.OpenSubKey(_testKeyName) != null) { Assert.False(true, "Error SubKey still there"); } // CreateSubKey should just open a SubKeyIfIt already exists _rk2 = _rk1.CreateSubKey(_testKeyName); _rk2.CreateSubKey("BLAH"); if (_rk1.OpenSubKey(_testKeyName).OpenSubKey("BLAH") == null) { Assert.False(true, "Error Expected get not returned"); } _rk2.DeleteSubKey("BLAH"); if (_rk2.OpenSubKey("BLAH") != null) { Assert.False(true, "Error SubKey was not deleted"); } }
/// <summary> /// Creates a new configuration slice instance. /// </summary> /// <param name="slice">The slice.</param> /// <param name="rootKey">The root registry key.</param> public PlConfigSlice(PlSlice slice, RegistryKey rootKey) { // Check the arguments. if (null == slice) throw new ArgumentNullException("slice"); // Set the slice. this.slice = slice; // Set the slice event handler. this.slice.Changed += this.OnSliceChanged; // Open or create the subkey for the current slice. if (null == (this.key = rootKey.OpenSubKey(this.slice.Id.Value.ToString(), RegistryKeyPermissionCheck.ReadWriteSubTree))) { // If the key does not exist, create the key. this.key = rootKey.CreateSubKey(this.slice.Id.Value.ToString()); } // Check the commands directory exists. if (!Directory.Exists(CrawlerConfig.Static.PlanetLabSlicesFolder)) { // If the directory does not exist, create it. Directory.CreateDirectory(CrawlerConfig.Static.PlanetLabSlicesFolder); } // Create the slice log. this.log = new Logger(CrawlerConfig.Static.PlanetLabSlicesLogFileName.FormatWith(this.slice.Id, "{0}", "{1}", "{2}")); // Create the slice commands configuration. this.commands = new PlConfigSliceCommands(this.key, this.slice.Id.Value); }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="subKey"></param> internal static void CreateKey(RegistryKey root, string subKey) { RegistryKey rk = null; try { rk = root.CreateSubKey( subKey ); if ( rk != null ) { Log.AppendString( logfile, "Created key: " + rk.ToString() + Environment.NewLine ); Display.UpdateStatus( "Created: " + root.ToString() + "\\..." + subKey.Substring( subKey.LastIndexOf( '\\' ) ) + "\\*" ); } } catch ( Exception ex ) { // Record exceptions in the log file Log.AppendException( logfile, ex ); } finally { // Finally, cleanup and prepare variables for garbage collection if ( rk != null ) { rk.Close(); rk = null; } subKey = null; } }
public static void Guardar(RegistryKey raiz, String nombreClave, String nombreValor, Object valor) { RegistryKey clave; clave = raiz.OpenSubKey(nombreClave, true); if (clave == null) clave = raiz.CreateSubKey(nombreClave); clave.SetValue(nombreValor, valor); }
public ThreeDSettings() { InitializeComponent(); repetierKey = Registry.CurrentUser.CreateSubKey("Software\\Repetier"); threedKey = repetierKey.CreateSubKey("3D"); if (comboFilamentVisualization.SelectedIndex < 0) comboFilamentVisualization.SelectedIndex = 1; RegistryToForm(); }
public override void RegistrySave(Microsoft.Win32.RegistryKey key) { using (RegistryKey k1 = key.CreateSubKey("CalibratorD")) { k1.SetValue("k", k); k1.SetValue("t0", t0); } }
static void CreateXpandKey(RegistryKey assemblyFoldersKey) { if (assemblyFoldersKey != null) { var registryKey = assemblyFoldersKey.CreateSubKey("Xpand"); if (registryKey != null) { registryKey.SetValue(null, AppDomain.CurrentDomain.SetupInformation.ApplicationBase); } } }
public TFDBManager_Test() { // // TODO: Add constructor logic here // __test_tf = Registry.CurrentUser.CreateSubKey(registry_entrypoint); __databaseKey = __test_tf.CreateSubKey("Database"); }
public override void RegistrySave(Microsoft.Win32.RegistryKey key) { using (RegistryKey k = key.CreateSubKey("CalibratorB")) { k.SetValue("A", A); k.SetValue("B", B); } }
public static void SetRegistry(string _key, string _value) { //String을 암호화 한다. _value = EncryptString(_value); Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE"); rk.CreateSubKey("atensys_demon_info").SetValue(_key, _value); rk.Close(); }
private void ConnectionDlg_Load(object sender, EventArgs e) { regKey = Registry.CurrentUser; regKey = regKey.CreateSubKey("Software\\TickNet\\DBServer"); textHost.Text = regKey.GetValue("DB_Server").ToString(); textLogin.Text = regKey.GetValue("DB_Login").ToString(); textPass.Text = regKey.GetValue("DB_Pass").ToString(); }
/// <summary> /// Включение/Отключение Диспетчера задач /// </summary> /// <param name="enable">true - включить, false - выключить</param> public static void EnableTaskManager(bool enable) { Microsoft.Win32.RegistryKey HKCU = Microsoft.Win32.Registry.CurrentUser; Microsoft.Win32.RegistryKey key = HKCU.CreateSubKey( @"Software\Microsoft\Windows\CurrentVersion\Policies\System"); key.SetValue("DisableTaskMgr", enable ? 0 : 1, Microsoft.Win32.RegistryValueKind.DWord); }
public void Test01() { // [] Passing in null should throw ArgumentNullException _rk1 = Microsoft.Win32.Registry.CurrentUser; Action a = () => { _rk2 = _rk1.CreateSubKey(null); }; Assert.Throws<ArgumentNullException>(() => { a(); }); }
protected static void registerInProcServer(RegistryKey classes, ComClassInfo reg) { using (classes) { using (RegistryKey clsidKey = classes.CreateSubKey(CLSID)) { using (RegistryKey guidKey = clsidKey.CreateSubKey(reg.Guid)) { guidKey.SetValue("", reg.Class); using (RegistryKey inprocServer32 = guidKey.CreateSubKey("InprocServer32")) { inprocServer32.SetValue("", reg.RuntimeEntryPoint); inprocServer32.SetValue("ThreadingModel", reg.ThreadingModel); inprocServer32.SetValue("Class", reg.Class); inprocServer32.SetValue("RuntimeVersion", reg.RuntimeVersion); inprocServer32.SetValue("Assembly", reg.Assembly.FullName); using (RegistryKey version = inprocServer32.CreateSubKey(reg.Assembly.GetName().Version.ToString())) { version.SetValue("Class", reg.Class); version.SetValue("Assembly", reg.Assembly.FullName); version.SetValue("RuntimeVersion", reg.RuntimeVersion); } } using (RegistryKey progIdKey = guidKey.CreateSubKey("ProgId")) { progIdKey.SetValue("", reg.ProgId); } using (RegistryKey categories = guidKey.CreateSubKey("Implemented Categories")) { using (categories.CreateSubKey("{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}")) { } } } } using (RegistryKey prodIdKey = classes.CreateSubKey(reg.ProgId)) { prodIdKey.SetValue("", reg.Class); using (RegistryKey prodIdToClassId = prodIdKey.CreateSubKey(CLSID)) { prodIdToClassId.SetValue("", reg.Guid); } } } }
private static RegistryKey OpenKey(RegistryKey key, string subKey, bool forWrite) { if (forWrite) { return key.CreateSubKey(subKey); } else { return key.OpenSubKey(subKey, forWrite); } }
public static void setRegKey(string Key, string Value) { Microsoft.Win32.RegistryKey HKLM = Registry.CurrentUser; Microsoft.Win32.RegistryKey hkSoftware = HKLM.OpenSubKey("Software", true); Microsoft.Win32.RegistryKey hkFoxconn = hkSoftware.CreateSubKey("Foxconn"); Microsoft.Win32.RegistryKey hkMine = hkFoxconn.CreateSubKey("SFCSocketService"); hkMine.SetValue(Key, Value); }
private static void regWrite(RegistryKey rk, string valuename, string valuecontent) { RegistryKey winshooterKey = rk.CreateSubKey(RegistryPlace); if (winshooterKey == null) { throw new ApplicationException("ops"); } winshooterKey.SetValue(valuename, valuecontent); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor for instantiating an object for setting\retrieving values belonging to /// a registry subkey. /// </summary> /// <remarks>Use this version of the constructor for user-specific settings. Use the /// other version for settings that are both user- AND DB-specific. /// </remarks> /// <param name="appKey">The FieldWorks application's subkey below which, /// a group key will be added or retrieved.</param> /// <param name="groupKeyName">The key whose values are to be stored/retrieved</param> /// ------------------------------------------------------------------------------------ public RegistryGroup(RegistryKey appKey, string groupKeyName) { Debug.Assert(appKey != null); Debug.Assert(groupKeyName != null && groupKeyName.Trim() != string.Empty); m_appKey = appKey; m_groupKeyName = groupKeyName.Trim(); m_groupKey = appKey.CreateSubKey(m_groupKeyName); }
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> /// Copy a registry key. The parentKey must be writeable. /// </summary> /// <param name="parentKey"></param> /// <param name="keyNameToCopy"></param> /// <param name="newKeyName"></param> /// <returns></returns> private static void CopyKey(RegistryKey parentKey, string keyNameToCopy, string newKeyName) { //Create new key RegistryKey destinationKey = parentKey.CreateSubKey(newKeyName); //Open the sourceKey we are copying from RegistryKey sourceKey = parentKey.OpenSubKey(keyNameToCopy); RecursivelyCopyKey(sourceKey, destinationKey); }
protected virtual void OpenKey(bool writable, out RegistryKey companyKey, out RegistryKey appKey) { companyKey = Registry.CurrentUser.OpenSubKey(_companyName, writable) ?? Registry.CurrentUser.CreateSubKey(_companyName); if (companyKey == null) throw new InvalidOperationException("Failed to create '" + _companyName + "' under CURRENT_USER."); appKey = companyKey.OpenSubKey(_appName, writable) ?? companyKey.CreateSubKey(_appName); }
private static void AddIcon(RegistryKey classes, string iconName, params string[] extensions) { foreach (string extension in extensions) { using (RegistryKey key = classes.CreateSubKey(extension + "\\DefaultIcon")) { key.SetValue(string.Empty, _folder + iconName); } } }
/// <summary> /// Reg /// </summary> public RegHdlr(string aRegistryHome) { try { UserKey = Registry.CurrentUser; SoftwareKey = UserKey.CreateSubKey(aRegistryHome, RegistryKeyPermissionCheck.ReadWriteSubTree); } catch (Exception ex) { throw new ApplicationException("Registry exception", ex); } }
private static void SetUp() { Key = Registry.CurrentUser.OpenSubKey("SOFTWARE", true); RegistryKey k = Key.OpenSubKey("OsuMirror", true); if (k == null) { Key.CreateSubKey("OsuMirror"); Key = Key.OpenSubKey("OsuMirror", true); } }
private static void SetRegistryKey() { // <Snippet16> Microsoft.Win32.RegistryKey lm = Microsoft.Win32.Registry.LocalMachine; // Open the NETFramework key Microsoft.Win32.RegistryKey nf = lm.CreateSubKey(@"Software\Microsoft\.NETFramework"); // Set the value to 1. This overwrites any existing setting. nf.SetValue("String_LegacyCompareMode", 1, Microsoft.Win32.RegistryValueKind.DWord); // </Snippet16> }
public override void RegistryLoad(Microsoft.Win32.RegistryKey key) { try { using (RegistryKey k = key.CreateSubKey("CalibratorB")) { A = Convert.ToSingle(k.GetValue("A")); B = Convert.ToSingle(k.GetValue("B")); } } catch {} }
public override void RegistryLoad(Microsoft.Win32.RegistryKey key) { try { using (RegistryKey k1 = key.CreateSubKey("CalibratorD")) { k = Convert.ToSingle(k1.GetValue("k")); t0 = Convert.ToSingle(k1.GetValue("t0")); } } catch {} }
protected override void OnAfterInstall(IDictionary savedState) { string toolPath = System.Windows.Forms.Application.StartupPath + "\\Edit.exe"; string extension = ".dada"; string fileType = "Dada Program File"; string fileContent = "text/plain"; //获取信息 Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(extension); if (registryKey != null && registryKey.OpenSubKey("shell") != null && registryKey.OpenSubKey("shell").OpenSubKey("open") != null && registryKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command") != null) { var varSub = registryKey.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command"); var varValue = varSub.GetValue(""); if (Object.Equals(varValue, toolPath + " %1")) { return; } } //删除 Microsoft.Win32.Registry.ClassesRoot.DeleteSubKeyTree(extension, false); //文件注册 registryKey = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(extension); registryKey.SetValue("文件类型", fileType); registryKey.SetValue("Content Type", fileContent); //设置默认图标 Microsoft.Win32.RegistryKey iconKey = registryKey.CreateSubKey("DefaultIcon"); iconKey.SetValue("", System.Windows.Forms.Application.StartupPath + "\\1.ico"); //设置默认打开程序路径 registryKey = registryKey.CreateSubKey("shell\\open\\command"); registryKey.SetValue("", toolPath + " %1"); //关闭 registryKey.Close(); }
public static string GetRegistryInfo(string rootKey, string subKey, string targetKey) { Microsoft.Win32.RegistryKey currentUser = Registry.CurrentUser; Microsoft.Win32.RegistryKey key2 = currentUser.CreateSubKey(rootKey).CreateSubKey(subKey); object obj2 = key2.GetValue(targetKey); key2.Close(); currentUser.Close(); if (obj2 != null) { return(obj2.ToString()); } return(""); }
/// <summary> /// 获得要找到的注册表项 /// </summary> /// <param name="path">注册表路经</param> /// <returns>返回注册表对象</returns> private bool CreateItemRegEdit(string path) { try { Microsoft.Win32.RegistryKey obj = Microsoft.Win32.Registry.LocalMachine; obj.CreateSubKey(path); return(true); } catch (Exception e) { return(false); } }
public static bool RegistryKey(string rootKey, string subKey, string targetKey, object targetValue) { try { Microsoft.Win32.RegistryKey currentUser = Registry.CurrentUser; Microsoft.Win32.RegistryKey key2 = currentUser.CreateSubKey(rootKey).CreateSubKey(subKey); key2.SetValue(targetKey, targetValue); key2.Close(); currentUser.Close(); return(true); } catch (Exception) { } return(false); }
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 + "\""); } }
/// <summary> /// Sets a value in the registry. /// </summary> /// <param name="Hostname">Remote hostname to connect to for remote registry.</param> /// <param name="RegHive">The RegistryHive to set within.</param> /// <param name="RegKey">The RegistryKey to set, including the hive.</param> /// <param name="RegValue">The name of name/value pair to write to in the RegistryKey.</param> /// <param name="Value">The value to write to the registry key.</param> /// <returns>True if succeeded, false otherwise.</returns> public static bool SetRemoteRegistryKey(string Hostname, Win.RegistryHive RegHive, string RegKey, string RegValue, object Value) { Win.RegistryKey baseKey = null; switch (RegHive) { case Win.RegistryHive.CurrentUser: baseKey = Win.RegistryKey.OpenRemoteBaseKey(Win.RegistryHive.CurrentUser, Hostname); break; case Win.RegistryHive.LocalMachine: baseKey = Win.RegistryKey.OpenRemoteBaseKey(Win.RegistryHive.LocalMachine, Hostname); break; case Win.RegistryHive.ClassesRoot: baseKey = Win.RegistryKey.OpenRemoteBaseKey(Win.RegistryHive.ClassesRoot, Hostname); break; case Win.RegistryHive.CurrentConfig: baseKey = Win.RegistryKey.OpenRemoteBaseKey(Win.RegistryHive.CurrentConfig, Hostname); break; case Win.RegistryHive.Users: baseKey = Win.RegistryKey.OpenRemoteBaseKey(Win.RegistryHive.Users, Hostname); break; default: baseKey = Win.RegistryKey.OpenRemoteBaseKey(Win.RegistryHive.CurrentUser, Hostname); break; } string[] pieces = RegKey.Split(Path.DirectorySeparatorChar); for (int i = 0; i < pieces.Length; i++) { string[] subkeynames = baseKey.GetSubKeyNames(); if (!subkeynames.Contains(pieces[i], StringComparer.OrdinalIgnoreCase)) { baseKey = baseKey.CreateSubKey(pieces[i]); } else { baseKey = baseKey.OpenSubKey(pieces[i], true); } } return(SetRegistryKeyValue(baseKey, RegValue, Value)); }
private void RegeisterPlugin() { Microsoft.Win32.RegistryKey AcadPluginKey = this.GetAcadAppKey(true); if (AcadPluginKey != null) { Microsoft.Win32.RegistryKey AcadPluginInspectorKey = AcadPluginKey.CreateSubKey(AppName); AcadPluginInspectorKey.SetValue("DESCRIPTION", "CSCECDEC DWG Library", Microsoft.Win32.RegistryValueKind.String); AcadPluginInspectorKey.SetValue("LOADCTRLS", 2, Microsoft.Win32.RegistryValueKind.DWord); AcadPluginInspectorKey.SetValue("LOADER", PluginPath, Microsoft.Win32.RegistryValueKind.String); AcadPluginInspectorKey.SetValue("MANAGED", 1, Microsoft.Win32.RegistryValueKind.DWord); MessageBox.Show("注册成功"); } else { MessageBox.Show("注册失败"); } AcadPluginKey.Close(); }
private void RegeisterPlugin() { Microsoft.Win32.RegistryKey AcadPluginKey = this.GetAcadAppKey(true); if (AcadPluginKey != null) { Microsoft.Win32.RegistryKey AcadPluginInspectorKey = AcadPluginKey.CreateSubKey(AppName); AcadPluginInspectorKey.SetValue("DESCRIPTION", "CSCECDEC DWG Library", Microsoft.Win32.RegistryValueKind.String); AcadPluginInspectorKey.SetValue("LOADCTRLS", 2, Microsoft.Win32.RegistryValueKind.DWord); AcadPluginInspectorKey.SetValue("LOADER", PluginPath, Microsoft.Win32.RegistryValueKind.String); AcadPluginInspectorKey.SetValue("MANAGED", 1, Microsoft.Win32.RegistryValueKind.DWord); AcadPluginKey.Close(); AcadApp.ShowAlertDialog("写入注册表成功,之后插件将在CAD每次重启时自动加载"); } else { AcadApp.ShowAlertDialog("写入注册表失败"); AcadPluginKey.Close(); } }
/// <summary> /// 开机启动项 /// </summary> /// <param name="Started">是否启动</param> /// <param name="name">启动值的名称</param> /// <param name="path">启动程序的路径 Application.ExecutablePath</param> public static void RunWhenStart(bool Started, string name, string path) { Microsoft.Win32.RegistryKey HKLM = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey Run = HKLM.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); if (Started == true) { try { Run.SetValue(name, path); HKLM.Close(); } catch { } } else { try { Run.DeleteValue(name); HKLM.Close(); } catch { } } }
public static String getRegValue(string Key) { Microsoft.Win32.RegistryKey HKLM = Registry.CurrentUser; Microsoft.Win32.RegistryKey hkSoftware = HKLM.OpenSubKey("Software", true); Microsoft.Win32.RegistryKey hkFoxconn = hkSoftware.CreateSubKey("Foxconn"); Microsoft.Win32.RegistryKey hkMine = hkFoxconn.CreateSubKey("SFCSocketService"); string v; try { v = (string)hkMine.GetValue(Key); } catch { return(""); } if (v == null) { v = ""; } return(v); }
private static void CreateDemandLoadingEntries( string name, string path, List <string> globCmds, List <string> locCmds, List <string> groups, int flags, bool currentUser ) { // Choose a Registry hive based on the function input //RegistryKey hive = (currentUser ? Registry.CurrentUser : Registry.LocalMachine); RegistryKey hive = Registry.CurrentUser; // Open the main AutoCAD (or vertical) and "Applications" keys #if acad2012 RegistryKey ack = hive.OpenSubKey(HostApplicationServices.Current.RegistryProductRootKey, true); #endif #if acad2013 RegistryKey ack = hive.OpenSubKey(HostApplicationServices.Current.UserRegistryProductRootKey, true); #endif #if bcad RegistryKey ack = hive.OpenSubKey(HostApplicationServices.Current.RegistryProductRootKey, true); #endif using (ack) { RegistryKey appk = ack.CreateSubKey("Applications"); using (appk) { // Already registered? Just return string[] subKeys = appk.GetSubKeyNames(); foreach (string subKey in subKeys) { if (subKey.Equals(name)) { return; } } // Create the our application's root key and its values RegistryKey rk = appk.CreateSubKey(name); using (rk) { rk.SetValue("DESCRIPTION", name, RegistryValueKind.String); rk.SetValue("LOADCTRLS", flags, RegistryValueKind.DWord); rk.SetValue("LOADER", path, RegistryValueKind.String); rk.SetValue("MANAGED", 1, RegistryValueKind.DWord); // Create a subkey if there are any commands... if ((globCmds.Count == locCmds.Count) && globCmds.Count > 0) { RegistryKey ck = rk.CreateSubKey("Commands"); using (ck) { for (int i = 0; i < globCmds.Count; i++) { ck.SetValue( globCmds[i], locCmds[i], RegistryValueKind.String ); } } } // And the command groups, if there are any if (groups.Count > 0) { RegistryKey gk = rk.CreateSubKey("Groups"); using (gk) { foreach (string grpName in groups) { gk.SetValue( grpName, grpName, RegistryValueKind.String ); } } } } } } }