In Vista, How Does the FLAGS Switch of REG.EXE Work?在Vista中,请问国旗开关reg.exe工作?
Note: this content originally from 注意:此内容原本由 http://mygreenpaste.blogspot.com http://mygreenpaste.blogspot.com . 。 If you are reading it from some other site, please take the time to visit 如果你是读它从其他一些网站上,请采取的时间访问 My Green Paste, Inc 我的绿色粘贴,公司 . 。 Thank you. 谢谢您。
A while back, there was a topic (而回,有一个话题( Virtual Registry vs. "Real registry"虚拟注册表与“真正的注册表” ) in the ) ,在 Sysinternals Forums的Sysinternals论坛 that brought up the question of how to set the virtualization-related flags of a registry key programmatically in Vista, rather than through the use of the REG.EXE tool's FLAGS switch.带来了问题,如何设置虚拟化有关的旗帜,一个注册表项以编程方式在Vista ,而不是通过使用该reg.exe工具的国旗开关。 (For more information on the flags, see (更多信息,对国旗,见 Mark Russinovich马克russinovich 's article in TechNet Magazine, "奇摩文章在TechNet杂志, “ Inside Windows Vista User Account Control内Windows Vista的使用者帐户控制 "). Even before that topic in the forum, I had wondered how it was done but had not had a chance to explore. It didn't seem that many others were curious about it. That topic had resurrected the idea, but it quickly fell to the bottom of the list. I've finally gotten around to experimenting, and that leads to this write-up. I still don't see much in the way of this discussed anywhere, by searching for terms involved (data types, function param names, etc.), so hopefully this will help someone. (Keep in mind that there very well may be a reason Microsoft hasn't made this available through another, more direct API.) “ ) ,即使之前的话题,在论坛上,我已不知道它是怎么做,但没有机会去探索。似乎没有什么,很多人好奇。这一议题已复活的想法,但很快下降到列表的底部,我已经终于周围的试点,导致这写了,我仍然没有看到很大的方式,这个讨论在任何地方,通过搜索的条款所涉及的(数据类型,功能参数的名称等) ,所以希望这将有助于有人。 (请记住,还有很可能是一个原因,微软并没有作出这可通过另一个,更直接的API ) 。
In the referenced topic, I had gotten so far as determining that REG.EXE was doing its work through the use of NtSetInformationKey, an "undocumented" API in NTDLL.DLL.在引用的话题,我曾得到到目前为止,作为认定reg.exe做其工作,通过使用ntsetinformationkey ,一个“无证件”在空气污染指数的Ntdll.dll 。
NTSYSAPI ntsysapi
NTSTATUS ntstatus
NTAPI ntapi
NtSetInformationKey( ntsetinformationkey (
IN HANDLE KeyHandle,在处理keyhandle ,
IN KEY_SET_INFORMATION_CLASS InformationClass,在key_set_information_class informationclass ,
IN PVOID KeyInformationData,在pvoid keyinformationdata ,
IN ULONG DataLength );在ulong datalength ) ;
After a bit of plonking around in WinDbg, I've come up with the following following details.后一点plonking左右,在windbg ,我已经有了以下以下细节。 REG.EXE calls reg.exe呼吁 NtSetInformationKey ntsetinformationkey , specifying a value of 2 for the InformationClass parameter. ,指定值2为informationclass参数。 This parameter is of type KEY_SET_INFORMATION_CLASS, which wdm.h tells us is an enum:这个参数的类型key_set_information_class , wdm.h告诉我们,是的ENUM :
typedef enum _KEY_SET_INFORMATION_CLASS { typedef的ENUM _key_set_information_class (
KeyWriteTimeInformation, keywritetimeinformation ,
KeyWow64FlagsInformation, keywow64flagsinformation ,
KeyControlFlagsInformation, keycontrolflagsinformation ,
KeySetVirtualizationInformation, keysetvirtualizationinformation ,
KeySetDebugInformation, keysetdebuginformation ,
MaxKeySetInfoClass // MaxKeySetInfoClass should always be the last enum maxkeysetinfoclass / / maxkeysetinfoclass要始终成为最后的ENUM
} KEY_SET_INFORMATION_CLASS; ) key_set_information_class ;
So the 2 for the InformationClass parameter would correspond to KeyControlFlagsInformation.因此,二为informationclass参数,将对应于keycontrolflagsinformation 。 WDM.H also suggests that this class has a type that one passes for the KeyInformationData parameter - KEY_CONTROL_FLAGS_INFORMATION: wdm.h还表明,这个类有一个类型,一通为keyinformationdata参数-k ey_control_flags_information:
typedef struct _KEY_CONTROL_FLAGS_INFORMATION { typedef结构_key_control_flags_information (
ULONG ControlFlags; ulong controlflags ;
} KEY_CONTROL_FLAGS_INFORMATION, *PKEY_CONTROL_FLAGS_INFORMATION; ) key_control_flags_information , * pkey_control_flags_information ;
We have a basic idea of how to call NtSetInformationKey now.我们有一个基本的想法如何调用ntsetinformationkey现在。 But what are the values that the ControlFlags member of KEY_CONTROL_FLAGS_INFORMATION can be set to?但什么是价值观认为, controlflags成员key_control_flags_information可以设定? It would appear that the following (self-made) enum covers the pertinent flags - at least the ones REG.EXE FLAGS can handle (there may be more):这样看来,以下(自制)的ENUM涵盖了相关的国旗-至少那些r eg.exe国旗可以处理(可能有更多的) :
typedef enum _CONTROL_FLAGS { typedef的ENUM _control_flags (
RegKeyClearFlags = 0, regkeyclearflags = 0 ,
RegKeyDontVirtualize = 2, regkeydontvirtualize = 2 ,
RegKeyDontSilentFail = 4, regkeydontsilentfail = 4 ,
RegKeyRecurseFlag = 8 regkeyrecurseflag = 8
} CONTROL_FLAGS; ) control_flags ;
The control flags are a bitmask, so you can OR them to set more than one.控制国旗是一个位掩码,所以你可以或他们设置一个以上。
Now that we have this information, what's left?现在我们有了这方面的资料,什么剩下的? We need to put it all together in a call to NtSetInformationKey.我们需要把它所有在同一个电话ntsetinformationkey 。 So, we need to get a pointer to the function in NTDLL.DLL.因此,我们必须取得一个指针的功能在的Ntdll.dll 。 Then, we can declare a struct of type KEY_CONTROL_FLAGS_INFORMATION, set the ControlFlags member to be what we wish, and open a key to the desired location in the registry, that can be passed to NtSetInformationKey.然后,我们可以宣布某一结构类型的key_control_flags_information ,设置controlflags会员要什么我们希望,并打开一个关键是要想要的位置在注册表中,即可以通过ntsetinformationkey 。 In the end, we wind up with something like the following (error handling has been omitted):在最后,我们的风起来像以下(错误处理已省略) :
typedef NTSYSAPI NTSTATUS (NTAPI* FuncNtSetInformationKey) ( typedef ntsysapi ntstatus ( ntapi * funcntsetinformationkey ) (
HANDLE KeyHandle,处理keyhandle ,
KEY_SET_INFORMATION_CLASS InformationClass, key_set_information_class informationclass ,
PVOID KeyInformationData, pvoid keyinformationdata ,
ULONG DataLength ); ulong datalength ) ;
//...
FuncNtSetInformationKey ntsik = (FuncNtSetInformationKey)GetProcAddress( funcntsetinformationkey ntsik = ( funcntsetinformationkey ) getprocaddress (
GetModuleHandle( _T("ntdll.dll") ), "NtSetInformationKey" ); getmodulehandle ( _t ( “的Ntdll.dll ” ) ) , “ ntsetinformationkey ” ) ;
KEY_CONTROL_FLAGS_INFORMATION kcfi = {0}; key_control_flags_information kcfi = ( 0 ) ;
kcfi.ControlFlags = RegKeyDontVirtualize | RegKeyRecurseFlag; kcfi.controlflags = regkeydontvirtualize | regkeyrecurseflag ;
HKEY hTheKey = NULL; hkey hthekey =空;
RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Whatever"), 0, KEY_ALL_ACCESS, &hTheKey ); regopenkeyex ( hkey_local_machine , _t (以下简称“软件\ \无论” ) , 0 , key_all_access , & hthekey ) ;
ntsik( hTheKey, KeyControlFlagsInformation, &kcfi, sizeof( KEY_CONTROL_FLAGS_INFORMATION ) ); ntsik ( hthekey , keycontrolflagsinformation , & kcfi , sizeof ( key_control_flags_information ) ) ;
RegCloseKey( hTheKey ); regclosekey ( hthekey ) ;
hTheKey = NULL; hthekey =空;
The code above is the equivalent of invoking REG.EXE FLAGS HKLM\Software\Whatever SET DONT_VIRTUALIZE RECURSE_FLAGS .上面的代码是相当于援引reg.exe国旗将HKLM \软件 \ 无论设置dont_virtualize recurse_flags 。 To clear the flags, just set kcfi.ControlFlags to RegKeyClearFlags (same as REG.EXE FLAGS HKLM\Software\Whatever SET) .以清除旗帜,刚刚成立kcfi.controlflags ,以regkeyclearflags (同reg.exe国旗将HKLM \软件\无论集) 。
Hopefully, this will prove useful to those that have wished to set these flags programmatically.希望这将证明是有用的,以那些有希望设置这些国旗编程。 In a future post, I hope to explore querying for these flags, ala REG.EXE FLAGS HKLM\Software\Whatever QUERY .在未来的职位,我希望探索质疑为国旗和区旗,助理法律顾问reg.exe国旗将HKLM \软件\无论查询 。
Note that this exploration was done on Windows Vista SP1.请注意,这是做了探索,在Windows Vista SP1的。 I would expect the content here to also apply to Windows Vista (no SP) as well as Windows Server 2008, but...我期望的内容,在这里也适用于Windows Vista的(没有SP ) ,以及在Windows Server 2008 ,但...
Popularity: 4%人气: 4 %
Written by «/\/\Ø|ö±ò\/»®©. 写â « / \ / \ ã 〜 | ã ¶ â ± ã ² \ / â » â ® â © 。 Read more great feeds at is source 阅读更多伟大的饲料是来源 WEBSITE 网站
no comments 没有评论 . 。
Read more articles on 阅读更多的文章 flags 国旗 and 和 NtSetInformationKey ntsetinformationkey and 和 REG_KEY_DONT_VIRTUALIZE reg_key_dont_virtualize and 和 Sysinternals Forum 的Sysinternals论坛 and 和 reg.exe flags reg.exe国旗 and 和 registry virtualization 注册表虚拟化 and 和 reg 条例 and 和 REG_KEY_DONT_SILENT_FAIL reg_key_dont_silent_fail and 和 Troubleshooting 疑难解答 and 和 vista Vista的 and 和 windbg windbg and 和 otherSoftware othersoftware and 和 registry 注册表 and 和 Virtualization 虚拟化 . 。
- [+] Digg [ + ] digg : Feature this article :特征此文章
- [+] Del.icio.us [ + ] del.icio.us : Bookmark this article :书签此文章
- [+] Furl [ + ] furl : Bookmark this article :书签此文章














