JBTALKS.CC

标题: [记录] C# Registry 权限 [打印本页]

作者: goodday    时间: 2009-8-21 09:43 PM
标题: [记录] C# Registry 权限
怕忘记 这边记录

•    HKEY_CLASSES_ROOT
    - Administrator Group - Full Control, Read
    - Power User Group - Read, Special Permissions
    - User Group - Read     
    - System Account - Full Control, Read
•    HKEY_CURRENT_CONFIG
    - Administrator Group- Full Control, Read
    - Power User Group - Read
    - User Group - Read     
    - System Account - Full Control, Read
•    HKEY_CURRENT_USER
    - Administrator Group - Full Control, Read     
    - Current User - Full Control, Read
    - System Account - Full Control, Read
•    HKEY_LOCAL_MACHINE
    - Administrator Group - Full Control, Read     
    - Everyone Group - Read     
    - System Account - Full Control, Read
•    HKEY_USERS
    - Administrator Group - Full Control, Read     
    - Everyone Group - Read     
    - System Account - Full Control, Read

引用
using Microsoft.Win32

写入和查寻



  1.     // Creates a subkey named myApplication under HKEY_CURRENT_USER.
  2.     RegistryKey regKey = Registry.CurrentUser.CreateSubKey("myApplication");

  3.     // There are two methods, which can be used to add subkeys and values
  4.     // to the registry. These are:
  5.     //
  6.     // RegistryKey.SetValue(string name, object value)
  7.     // RegistryKey.SetValue(string name, object value, RegistryValueKind valueKind)

  8.     // First Method:
  9.     // Creates a subkey under the new registry key myApplication and
  10.     // writes a value to the new subkey.
  11.     regKey.SetValue("myValue", "This is a test");

  12.     // Multiple subKeys can be created at a time
  13.     // as shown in the example code below:
  14.     //
  15.     // regKey.SetValue("myValue1", "Test Value 1");
  16.     // regKey.SetValue("myValue2", "Test Value 2");


  17.     // Second Method:
  18.     // Creates subkeys under the registry key myApplication and
  19.     // writes common value types.
  20.     //
  21.     // regKey.SetValue("DWordValue", 10, RegistryValueKind.DWord);
  22.     // regKey.SetValue("MultipleStringValue", new string[] { "One", "Two", "Three" }, RegistryValueKind.MultiString);
  23.     // regKey.SetValue("BinaryValue", new byte[] { 8, 16, 32, 64, 128, 256 }, RegistryValueKind.Binary);
  24.     // regKey.SetValue("StringValue", "The directory path is %PATH%", RegistryValueKind.String);
  25.     // regKey.SetValue("ExpandedStringValue", "The directory path is %PATH%", RegistryValueKind.ExpandString);
复制代码


拿出来


  1.         // Opens the subkey called myApplication.
  2.         RegistryKey regKey = Registry.CurrentUser.OpenSubKey("myApplication");

  3.         // Checks to see if the value of the subkey is null.
  4.         if (regKey == null)
  5.         {
  6.             // If the subkey does not exist than a MessageBox will be displayed.
  7.             MessageBox.Show("The registry key that you are trying to "
  8.                 + Environment.NewLine + "read does not exist.",
  9.                     "Registry Key Does Not Exist", MessageBoxButtons.OK,
  10.                     MessageBoxIcon.Information);
  11.         }
  12.         else
  13.         {
  14.             // Reads the subkey value for myValue from the registy
  15.             // key HKEY_CURRENT_USER/myApplication.
  16.             MessageBox.Show(regKey.GetValue("myValue").ToString(), "Registry SubKey Value",
  17.               MessageBoxButtons.OK, MessageBoxIcon.Information);
  18.         }
复制代码


delete

  1.         // Opens the subkey called myApplication
  2.         RegistryKey regKey = Registry.CurrentUser.OpenSubKey("myApplication", true);
  3.          
  4.         // Checks to see if the value of the subkey is null
  5.         if (regKey == null)
  6.         {
  7.             // If the subkey does not exist than a MessageBox will be displayed.
  8.             MessageBox.Show("The registry key that you are trying to "
  9.                 + Environment.NewLine + "delete does not exist.",
  10.                     "Registry Key Does Not Exist", MessageBoxButtons.OK,
  11.                     MessageBoxIcon.Information);
  12.         }
  13.         else
  14.         {
  15.             // Verifies that the registry key is not already deleted.
  16.             if (!Convert.ToBoolean(Registry.CurrentUser.OpenSubKey("myApplication") == null))
  17.             {
  18.                 // Deletes the subkey and any child subkeys under
  19.                 // the registry key HKEY_CURRENT_USER/myApplication.
  20.                 Registry.CurrentUser.DeleteSubKeyTree("myApplication");

  21.                 // Deletes a subkey and it's value under the registry
  22.                 // key myApplication.
  23.                 //regKey.DeleteValue("myValue");

  24.                 // If the deletion was successful than a MessageBox
  25.                 // will be displayed.
  26.                 MessageBox.Show("The registry key was deleted successfully.",
  27.                     "Registry Key Deleted", MessageBoxButtons.OK,
  28.                     MessageBoxIcon.Information);
  29.             }

  30.             else
  31.             {
  32.                 // If the subkey does not exist than a MessageBox will be displayed.
  33.                 MessageBox.Show("The registry key that you are trying to "
  34.                 + Environment.NewLine + "delete does not exist.",
  35.                     "Registry Key Does Not Exist", MessageBoxButtons.OK,
  36.                     MessageBoxIcon.Information);
  37.             }
  38.         }
复制代码


转载
http://vbcity.com/forums/faq.asp?fid=31&cat=Registry
作者: yk_tan1987    时间: 2009-8-21 10:23 PM
请问delete了这些会电脑有什么影响吗?
作者: goodday    时间: 2009-8-22 05:21 PM
Ref : http://www.sysdevsoftware.com/soft/dreg.php
Registry file location map (assume Windows is intalled on C:\WINDOWS; user profiles are in C:\Documents and Settings):

HKEY_CLASSES_ROOT – virtual key. Actual location is in HKEY_LOCAL_MACHINE\Software\Classes (see below);
HKEY_CURRENT_USER – the key corresponds to C:\Documents and Settings\UserName\NTUSER.DAT of user currently logged in. You may access registry data of any user;
HKEY_LOCAL_MACHINE – virtual key. Is combined from few files:
HKEY_LOCAL_MACHINE\HARDWARE – virtual branch; no file there.
HKEY_LOCAL_MACHINE\SAM – corresponds to C:\WINDOWS\system32\config\sam file;
HKEY_LOCAL_MACHINE\SECURITY – corresponds to C:\WINDOWS\system32\config\SECURITY file;
HKEY_LOCAL_MACHINE\SOFTWARE – corresponds to C:\WINDOWS\system32\config\software file;
HKEY_LOCAL_MACHINE\SYSTEM – corresponds to C:\WINDOWS\system32\config\SYSTEM file;
Note: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet is just symbolic link to HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001.
Other files are mainly not so important for users/administrators. You may find other file conponents in C:\WINDOWS\system32\config\ directory.
To access the file you have to open it. You now may browse and recover data from the file (select key and choose ‘Export key’ or select value and choose ‘Save’).

When you do key export, you have to select ‘virtual Windows registry prefix’ to make it work with RegEdit Windows utility correctly.

记录 记录




欢迎光临 JBTALKS.CC (https://www.jbtalks.cc/) Powered by Discuz! X2.5