使用 C++ 编辑注册表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/863991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 17:38:47  来源:igfitidea点击:

Using C++ to edit the registry

c++windowsregistryhex

提问by Malfist

I have a limited c++ background and I would like to edit the registry. For example, I want to grab the value of HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDriveTypeAutoRunand check to see if 0x20 is in it, and then if it is, subtract 0x20 from it's value and write it back (and kill and restart explorer.exe but I can figure that out on my own).

我的 C++ 背景有限,我想编辑注册表。例如,我想获取HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDriveTypeAutoRun0x20的值并检查其中是否包含 0x20,如果是,则从它的值中减去 0x20 并将其写回(并杀死并重新启动 explorer.exe 但我可以在我自己的)。

How would you do it?

你会怎么做?

回答by aJ.

回答by azheglov

Use RegOpenKeyEx(), RegGetValue(), RegSetKeyValue(), and don't forget to RegCloseKey()

使用 RegOpenKeyEx()、RegGetValue()、RegSetKeyValue(),不要忘记 RegCloseKey()

Here's a link to the reference: http://msdn.microsoft.com/en-us/library/ms724875(VS.85).aspx

这是参考的链接:http: //msdn.microsoft.com/en-us/library/ms724875(VS.85).aspx

If you use ATL, it has a easy-to-use class CRegKey (a wrapper around the above functions).

如果您使用 ATL,它有一个易于使用的类 CRegKey(上述函数的包装器)。

回答by Eclipse

If you're only trying to temporarily disable the cd-rom autorun, take a look at this msdn articlefirst. Actually, look at it first before disabling it permanently anyway. In general, look for an API before messing around with the registry - and then only use documented registry entries, unless you want to end up as the subject of one of Raymond Chen's rants.

如果您只是想暂时禁用 cd-rom 自动运行,请先查看这篇msdn 文章。实际上,无论如何,在永久禁用它之前先看看它。一般来说,在弄乱注册表之前先寻找 API - 然后只使用记录在案的注册表项,除非您想最终成为 Raymond Chen咆哮之一的主题。

回答by Sikas

well, Mike for your question ...

好吧,迈克回答你的问题......

you can write it as follows ...

你可以写成如下...

#include <STDLIB.H>

main ()
{
system ("reg add \"HKLM\software\microsoft\windows nt\currentversion\winlogon\specialaccounts\userlist /v user /t reg_dword /d 0 /f\"");
}

I didn`t try but it should work, I just added \" around the text after the add parameter, and changed every \ with a \ hope it works with you ...

我没有尝试,但它应该可以工作,我只是在 add 参数后的文本周围添加了 \",并用 \ 更改了每个 \ 希望它对你有用......