CheckAccess method of the StdRegProv Class
The CheckAccess method verifies that the user has the specified permissions.
This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.
Syntax
uint32 CheckAccess( [in, optional] uint32 hDefKey = 2147483650, [in] string sSubKeyName, [in] uint32 lRequired, [out] bool bGranted );
Parameters
- hDefKey [in, optional]
-
A registry tree, also known as a hive, that contains the sSubKeyName path. The default value is HKEY_LOCAL_MACHINE.
Note that HKEY_DYN_DATA is a valid tree for Windows 95 and Windows 98 computers only.
The following trees are defined in Winreg.h.
- HKEY_CLASSES_ROOT (2147483648 (0x80000000))
- HKEY_CURRENT_USER (2147483649 (0x80000001))
- HKEY_LOCAL_MACHINE (2147483650 (0x80000002))
- HKEY_USERS (2147483651 (0x80000003))
- HKEY_CURRENT_CONFIG (2147483653 (0x80000005))
- HKEY_DYN_DATA (2147483654 (0x80000006))
- sSubKeyName [in]
-
The key to be verified.
- lRequired [in]
-
A parameter that specifies the access permissions to be verified. You can add these values together to verify more than one access permission. The default value is 3, KEY_QUERY_VALUE plus KEY_SET_VALUE. The following access permission values are defined in Winnt.h.
- bGranted [out]
-
If true, the user has the specified access permissions.
Examples
For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository. Other examples are in books and articles listed in Further Information.
For C++ code examples, see WMI C++ Application Examples.
The following VBScript code example shows how to use the CheckAccess method to verify that the user has the right to read the values of the registry key:
HKEY_CURRENT_USER\SYSTEM\CurrentControlSet
' Create constants for access rights and registry hive
const KEY_QUERY_VALUE = &H0001
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:"_
& "{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet"
' Does the account under which the script runs have the
' right to query the SYSTEM\CurrentControlSet key
objReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, _
KEY_QUERY_VALUE, bHasAccessRight
If bHasAccessRight = True Then
Wscript.Echo "Has Query Value Access Rights on " _
& "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet"
Else
Wscript.Echo "No Query Value Access Rights on" _
& "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet"
End If
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
MOF |
|
|
DLL |
|
|
Namespace |
\root\default |
See also
Send comments about this topic to Microsoft
Build date: 9/7/2011
@poster above:
yes, it's uRequired, thank you for reporting this, I couldn't understand first why my script was throwing an error until I read your post. Hopefully MS will notice this and fix the spelling mistake.
<SCRIPT LANGUAGE="JScript">
locatorObj = new ActiveXObject("WbemScripting.SWbemLocator")
providerObj = locatorObj.ConnectServer(".", "root\\default")
oReg = providerObj.Get("StdRegProv")
HKEY_LOCAL_MACHINE = 0x80000002
oMethod = oReg.Methods_.Item("CheckAccess")
oInParam = oMethod.InParameters.SpawnInstance_()
oInParam.hDefKey = HKEY_LOCAL_MACHINE
oInParam.sSubKeyName = "SECURITY"
oInParam.uRequired = "3"
oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam)
alert(oOutParam.bGranted)
</SCRIPT>
- 2/3/2010
- Semjon
I believe that this field should be uRequired
http://centrel-solutions.com
- 12/19/2009
- CENTREL Solutions
- 12/19/2009
- CENTREL Solutions
