SWbemPrivilegeSet object
An SWbemPrivilegeSet object is a collection of SWbemPrivilege objects in an SWbemSecurity object that requests specific privileges for a Windows Management Instrumentation (WMI) object. See the list of privileges in Privilege Constants. Items are added to the collection using the Add and AddAsString methods. Items are retrieved from the collection using the Item method, and removed using the Remove method. This object cannot be created by the VBScript CreateObject method call. For more information, see Accessing a Collection.
An SWbemPrivilegeSet object is a set of privilege override requests for a specific object. When an API call is made using this object, the privilege override requests are attempted. The SWbemPrivilegeSet object does not define the privileges available to the current user or process. In other words, obtaining the privileges for any WMI object does not identify the privilege settings that are made on the connection to WMI, or the privileges in effect when an object is delivered to a sink.
Members
The SWbemPrivilegeSet object has these types of members:
Methods
The SWbemPrivilegeSet object has these methods.
Method | Description |
---|---|
Add | Adds an SWbemPrivilege object to the SWbemPrivilegeSet collection using a WbemPrivilegeEnum constant. |
AddAsString | Adds an SWbemPrivilege object to the SWbemPrivilegeSet collection using a privilege string. |
DeleteAll | Deletes all the privileges from the collection. |
Item | Retrieves an SWbemPrivilege object from the collection. This is the default method of this object. |
Remove | Removes an SWbemPrivilege object from the collection. |
Properties
The SWbemPrivilegeSet object has these properties.
Property | Access type | Description |
---|---|---|
Count |
Read-only |
The number of items in the collection. |
Examples
The following VBScript code example obtains an SWbemPrivileges object and adds all the available privileges to the collection by privilege value, as defined in WbemPrivilegeEnum.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" _
& strComputer & "\root\cimv2")
set colPrivileges = objWMIService.Security_.Privileges
For I = 1 To 27
colPrivileges.Add(I)
Next
' Display information about each privilege
For Each objItem In colPrivileges
wscript.echo objItem.Identifier & vbtab & objItem.Name _
& vbtab & objItem.Displayname _
& vbtab & "Enabled = " & objItem.IsEnabled
Next
The following VBScript code example demonstrates how to add privileges using the SWbemPrivilegeSet object.
on error resume next
const wbemPrivilegeSecurity = 8
const wbemPrivilegeDebug = 20
set locator = CreateObject("WbemScripting.SWbemLocator")
' Add a single privilege using SWbemPrivilegeSet.Add
locator.Security_.Privileges.Add wbemPrivilegeSecurity
Set Privilege = locator.Security_.Privileges(wbemPrivilegeSecurity)
WScript.Echo Privilege.Name
' Attempt to add an illegal privilege using SWbemPrivilegeSet.Add
locator.Security_.Privileges.Add 6535
if err <> 0 then
WScript.Echo "0x" & Hex(Err.Number), Err.Description, Err.Source
err.clear
end if
locator.Security_.Privileges.Add wbemPrivilegeDebug
locator.Security_.Privileges(wbemPrivilegeDebug).IsEnabled = false
' Add a single privilege using SWbemPrivilegeSet.AddAsString
Set Privilege = locator.Security_.Privileges.AddAsString ("SeChangeNotifyPrivilege")
WScript.Echo Privilege.Name
' Attempt to add an illegal privilege using SWbemPrivilegeSet.AddAsString
locator.Security_.Privileges.AddAsString "SeChungeNotifyPrivilege"
if err <> 0 then
WScript.Echo "0x" & Hex(Err.Number), Err.Description, Err.Source
err.clear
end if
WScript.Echo ""
for each Privilege in locator.Security_.Privileges
WScript.Echo "[" & Privilege.DisplayName & "]", Privilege.Identifier, Privilege.Name, Privilege.IsEnabled
next
if err <> 0 then
WScript.Echo Err.Number, Err.Description, Err.Source
end if
The following Perl code example demonstrates how to add privileges using the SWbemPrivilegeSet object.
use strict;
use Win32::OLE;
close(STDERR);
my ($locator, $Privilege);
my $wbemPrivilegeSecurity = 8;
my $wbemPrivilegeDebug = 20;
eval { $locator = new Win32::OLE 'WbemScripting.SWbemLocator';};
if (!$@ && defined $locator)
{
# Add a single privilege using SWbemPrivilegeSet.Add
$locator->{Security_}->{Privileges}->Add($wbemPrivilegeSecurity);
$Privilege = $locator->{Security_}->Privileges($wbemPrivilegeSecurity);
print "\n", $Privilege->{Name}, "\n\n";
# Attempt to add an illegal privilege using SWbemPrivilegeSet.Add
eval { $locator->{Security_}->{Privileges}->Add(6535); };
print Win32::OLE->LastError, "\n" if ($@ || Win32::OLE->LastError);
$locator->{Security_}->{Privileges}->Add($wbemPrivilegeDebug);
$locator->{Security_}->Privileges($wbemPrivilegeDebug)->{IsEnabled} = 0;
# Add a single privilege using SWbemPrivilegeSet.AddAsString
$Privilege = $locator->{Security_}->{Privileges}->AddAsString ("SeChangeNotifyPrivilege");
print "\n", $Privilege->{Name}, "\n\n";
# Attempt to add an illegal privilege using SWbemPrivilegeSet.AddAsString
eval {$locator->{Security_}->{Privileges}->AddAsString ("SeChungeNotifyPrivilege"); };
print Win32::OLE->LastError, "\n" if ($@ || Win32::OLE->LastError);
print "\n";
foreach $Privilege (in {$locator->{Security_}->{Privileges}})
{
printf "[%s] %d %s %d \n" , $Privilege->{DisplayName}, $Privilege->{Identifier}, $Privilege->{Name}, $Privilege->{IsEnabled};
}
}
else
{
print Win32::OLE->LastError, "\n";
}
Requirements
Requirement | Value |
---|---|
Minimum supported client |
Windows Vista |
Minimum supported server |
Windows Server 2008 |
Header |
|
Type library |
|
DLL |
|
CLSID |
CLSID_SWbemPrivilegeSet |
IID |
IID_ISWbemPrivilegeSet |