问题描述
我正在尝试读取注册表路径
I am trying to read the registry path
HKEY_CURRENT_USER \ Software \ MyFolder
HKEY_CURRENT_USER\Software\MyFolder
通过运行以下代码
RegistryKey key1 = Registry.CurrentUser.OpenSubKey(path);
if (key1 != null)
{
RegistryKey key2 = key1.OpenSubKey(subPath);
if (key2 != null)
{
return key2.GetValue(registryKey);
}
}
其中path =软件和subPath = MyFolder
Where path = Software and subPath = MyFolder
- key2始终为NULL
- 我相信此代码实际上是从HKEY_LOCAL_MACHINE \ Software \ MyFolder中读取的,因为它将在IIS帐户下默认为该代码(我在应用程序池标识下运行)
如何强制此代码访问HKEY_CURRENT_USER?我需要更改应用程序池的身份吗?还是其他方式?
How to I force this code to access HKEY_CURRENT_USER? Do I need to change the identity of the app pool? Or some other way?
推荐答案
这是一个Web应用程序-我将远离注册表.将信息放入配置文件或数据库中.其他人已经解释了为什么您无法打开它.这是有关它的更多信息.
This is a web app - I would stay far away from the registry. Put the information in a configuration file or a database. Others have explained why you can't open it. Here is a little more information around it.
•HKEY_LOCAL_MACHINE(HKLM):包含与系统上安装的所有硬件设备和软件程序有关的配置信息.
• HKEY_LOCAL_MACHINE (HKLM): Contains configuration information related to all hardware devices and software programs that are installed on your system.
•HKEY_USERS(HKU):包含与系统上配置的所有用户配置文件有关的信息. HKEY_USERS键具有一个模板,系统将使用该模板来生成具有默认配置的新用户配置文件.
• HKEY_USERS (HKU): Contains information related to all user profiles configured on the system. HKEY_USERS key has a template, which is used by your system to generate new user profiles with default configuration.
•HKEY_CLASSES_ROOT(HKCR):存储有关在计算机上注册的文件类型和扩展名,协议和类的信息.该密钥是用户特定的,并从HKLM密钥中提取用户特定的数据. HKCR子树中显示的信息是从HKLMSOFTWAREClasses和HKCUSOFTWAREClasses键获得的.
• HKEY_CLASSES_ROOT (HKCR): Stores information about file types and extensions, protocols, and classes registered on your computer. This key is user-specific and extracts user-specific data from the HKLM key. The information displayed in the HKCR subtree is obtained from the HKLMSOFTWAREClasses and HKCUSOFTWAREClasses keys.
•HKEY_CURRENT_USER(HKCU):HKEY_CURRENT_USER项包含与桌面设置,变量,变量,环境用户文件夹以及当前用户的其他特定于用户的设置有关的信息.与HKCR一样,此密钥从HKU密钥中提取特定于用户的信息.从系统登录用户的HKUSecurity ID密钥中提取此密钥显示的信息.
• HKEY_CURRENT_USER (HKCU): HKEY_CURRENT_USER key contains information related to desktop settings, variables, variables, environment user folders, and other user-specific settings for the current user. Like HKCR, this key extracts user-specific information from the HKU key. The information displayed by this key is pulled out from the HKUSecurity ID key of the user logged in on the system.
•HKEY_CURRENT_CONFIG(HKCC):该密钥包含有关当前用户的硬件配置的信息.该密钥从HKLMSYSTEM CurrentControlSet CurrentControlSetHardware Profiles密钥中提取相关信息.
• HKEY_CURRENT_CONFIG (HKCC): This key contains information about hardware configuration for the current user. This key extracts relevant information from the HKLMSYSTEM CurrentControlSet CurrentControlSetHardware Profiles key.
如果您决定仍然使用注册表,则将信息存储在HKLM中.
If you do decide to still use the registry - store the information in HKLM.
这篇关于在IIS下读取HKEY_CURRENT_USER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!