本文介绍了编写HKEY_LOCAL_MACHINE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用C#将一些数据写入HKEY_LOCAL_MACHINE.

I need to write some data to the HKEY_LOCAL_MACHINE in C#.

但是,如果我没有以管理员身份运行,则会发生权限错误.

However a permission error occurs if I don't run as administrator.

我不希望设置< requestedExecutionLevel level =" requireAdministrator" uiAccess =假". />在app.manifest中,因为它在我的应用程序的快捷方式图标上创建了UAC屏蔽图标.

I don't want set <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> in the app.manifest because it create UAC shield icon on the shortcut icon of my application.

如何在程序中解决此问题?

How do I solve this in my program?

是否可以在不以管理员身份运行的情况下写HKEY_LOCAL_MACHINE?

Is it possible to write HKEY_LOCAL_MACHINE without run as administrator?

推荐答案

>>是否可以在不以管理员身份运行的情况下编写HKEY_LOCAL_MACHINE?

>>Is it possible to write HKEY_LOCAL_MACHINE without run as administrator?

恐怕您必须以管理员身份运行(或使用具有管理特权的帐户),这是一种安全措施,可以防止恶意软件利用那些愚蠢地始终以管理特权使用其计算机的用户.

I am afraid you must run as Administrator (or using an account with administrative privileges) This is a security measure, preventing malware from exploiting users who foolishly use their computer all the time with administrative privileges.

>>如何在程序中解决此问题?

>>How do I solve this in my program?

您知道我们的Windows是多用户操作系统,仅为当前用户编写设置.无论如何,这很有意义,因为不同的用户通常具有不同的设置和首选项.而不是您想使用注册表的HKEY_LOCAL_MACHINE分支(需要访问管理权限)HKEY_CURRENT_USER.将第一行代码更改为:

As you know our Windows is a multi-user operating system and writing your settings only for the current user. This makes good sense anyway because different users often have different settings and preferences. Instead of theHKEY_LOCAL_MACHINE branch of the registry (which requires administrative privileges to access), you would want to useHKEY_CURRENT_USER. Change your first line of code to:

RegistryKey softwareKey = Registry.CurrentUser.OpenSubKey("XXXX", true);

最诚挚的问候,

克里斯汀


这篇关于编写HKEY_LOCAL_MACHINE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 17:47