Share via


SWbemPrivilegeSet オブジェクト

SWbemPrivilegeSet オブジェクトは、Windows Management Instrumentation (WMI) オブジェクトの特定の特権を要求する SWbemSecurity オブジェクト内の SWbemPrivilege オブジェクトのコレクションです。 「特権定数」で、特権の一覧をご確認ください。 項目は、AddAddAsString メソッドを使用してコレクションに追加されます。 項目は Item メソッドを使用してコレクションから取得され、Remove メソッドを使用して削除されます。 このオブジェクトは、VBScript の CreateObject メソッドでは作成できません。 詳細については、コレクションへのアクセスに関する記事を参照してください。

SWbemPrivilegeSet オブジェクトは、特定のオブジェクトに対する一連の特権オーバーライド要求です。 このオブジェクトを使用して API 呼び出しが行われると、特権オーバーライド要求が試行されます。 SWbemPrivilegeSet オブジェクトは、現在のユーザーまたはプロセスが使用できる特権を定義しません。 言い換えると、WMI オブジェクトの特権を取得しても、WMI への接続で行われる特権設定や、オブジェクトがシンクに配信されるときに有効な特権は指定されません。

メンバー

SWbemPrivilegeSet オブジェクトには、次の種類のメンバーがあります。

メソッド

SWbemPrivilegeSet オブジェクトには、次のメソッドがあります。

メソッド 説明
追加 WbemPrivilegeEnum 定数を使用して、SWbemPrivilegeSet コレクションに SWbemPrivilege オブジェクトを追加します。
AddAsString 特権文字列を使用して、SWbemPrivilegeSet コレクションに SWbemPrivilege オブジェクトを追加します。
DeleteAll コレクションからすべての特権を削除します。
Item コレクションから SWbemPrivilege オブジェクトを取得します。 これは、このオブジェクトの既定のメソッドです。
[削除] コレクションから SWbemPrivilege オブジェクトを削除します。

プロパティ

SWbemPrivilegeSet オブジェクトには、次のプロパティがあります。

プロパティ アクセスの種類 説明
Count
読み取り専用
コレクション内の項目数。

次の VBScript コード例は、SWbemPrivileges オブジェクトを取得し、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

次の VBScript コード例は、SWbemPrivilegeSet オブジェクトを使用して特権を追加する方法を示しています。

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 

次の Perl コード例は、SWbemPrivilegeSet オブジェクトを使用して特権を追加する方法を示しています。

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";
}

要件

要件
サポートされている最小のクライアント
Windows Vista
サポートされている最小のサーバー
Windows Server 2008
Header
Wbemdisp.h
タイプ ライブラリ
Wbemdisp.tlb
[DLL]
Wbemdisp.dll
CLSID
CLSID_SWbemPrivilegeSet
IID
IID_ISWbemPrivilegeSet

関連項目

特権操作の実行

VBScript を使用した特権操作の実行

WbemPrivilegeEnum

API オブジェクトのスクリプト作成

特権定数