Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 3048|回复: 2
打印 上一主题 下一主题

[记录] C# Registry 权限

[复制链接]

13

主题

0

好友

2113

积分

白金长老

Rank: 10

跳转到指定楼层
1#
发表于 2009-8-21 09:43 PM |只看该作者 |倒序浏览
怕忘记 这边记录

•    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




收藏收藏0

1084

主题

22

好友

4万

积分

荣誉会员

苦力™

Rank: 50Rank: 50Rank: 50Rank: 50Rank: 50

2011尽忠职守奖 2011身兼多职奖 赫赫之功

2#
发表于 2009-8-21 10:23 PM |只看该作者
请问delete了这些会电脑有什么影响吗?


回复

使用道具 举报

13

主题

0

好友

2113

积分

白金长老

Rank: 10

3#
发表于 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 |联系我们 |隐私政策 |Share

GMT+8, 2025-1-10 05:34 AM , Processed in 0.103081 second(s), 29 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部