Description
It is sometimes necessary to set the impersonation level that WMI will use. Without the necessary impersonation level, WMI may refuse a request or provide incomplete information.
WMI defaults to wbemImpersonateLevelImpersonate under the current WMI release (May 2001) if you do not set the impersonation level in your code and have not modified the registry.
In short, the setting the impersonation level of WMI tells the system whos credentials to use when making the call. This allows the administrator to restrict who can make certain changes to the system.
WMI integrates with NT security and permissions can be set to nodes. Currently, WMI only supports setting root or near root level node permissions.
| Name |
Value |
Description |
| wbemImpersonationLevelAnonymous |
1 |
Hides the credentials of the caller. Calls to WMI may fail with this impersonation level. |
| wbemImpersonationLevelIdentify |
2 |
Allows objects to query the credentials of the caller. Calls to WMI may fail with this impersonation level. |
| wbemImpersonationLevelImpersonate |
3 |
Allows objects to use the credentials of the caller. This is the recommended impersonation level for WMI Scripting API calls. |
| wbemImpersonationLevelDelegate |
4 |
Allows objects to permit other objects to use the credentials of the caller. This impersonation, which will work with WMI Scripting API calls but may constitute an unnecessary security risk, is supported only under Windows 2000. |
var Service = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
or
var Service = GetObject("winmgmts:\\\\.\\root\\cimv2");
Service.Security_.ImpersonationLevel = 3;