Bewerken

Share via


SWbemPrivilegeSet.AddAsString method

You can use the AddAsString method of the SWbemPrivilegeSet object to add a privilege to an SWbemPrivilegeSet collection using a privilege string. Use this method to add a privilege or to enable a privilege for SWbemSecurity objects. See Executing Privileged Operations Using VBScript.

For an explanation of this syntax, see Document Conventions for the Scripting API.

Syntax

objPrivilege = .AddAsString( _
  ByVal strPrivilege, _
  [ ByVal bIsEnabled ] _
)

Parameters

strPrivilege

Required. One of the privilege strings. For a complete list of these strings and the associated WMI constants, see Privilege Constants. Every privilege string represents a specific privilege. For example, to add the privilege that use to shut down a computer system, use the SeShutdownPrivilege string.

bIsEnabled [optional]

Boolean value that enables or disables this privilege. The default value is True.

Return value

If successful, this method returns an SWbemPrivilege object that represents the new privilege. Otherwise, a null object is returned.

Error codes

Upon the completion of the AddAsString method, the Err object may contain the error code in the following list.

wbemErrFailed - 2147749889 (0x80041001)

Unspecified error.

Examples

The following VBScript code example creates a new port for a print server using Win32_TCPIPPrinterPort. The SeLoadDriverPrivilege is required for this operation. See Executing Privileged Operations.

Set objWMIService = GetObject("Winmgmts:")
objWMIService.Security_.Privileges. _
    AddAsString "SeLoadDriverPrivilege", True
Set objNewPort = objWMIService.Get _
    ("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = "IP_111.222.111.11"
objNewPort.Protocol = 1
objNewPort.HostAddress = "111.222.111.11"
objNewPort.PortNumber = "9999"
objNewPort.SNMPEnabled = False
objNewPort.Put_

A code example using this method is also described in the SWbemPrivilegeSet topic.

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Header
Wbemdisp.h
Type library
Wbemdisp.tlb
DLL
Wbemdisp.dll
CLSID
CLSID_SWbemPrivilegeSet
IID
IID_ISWbemPrivilegeSet

See also

SWbemPrivilegeSet

SWbemPrivilegeSet.Add

SWbemPrivilegeSet.Remove

WbemPrivilegeEnum

Privilege Constants

Executing Privileged Operations

Executing Privileged Operations Using VBScript