SWbemNamedValueSet 物件

SWbemNamedValueSet物件是SWbemNamedValue物件的集合。 SWbemNamedValueSet的方法和屬性主要用來在提交特定 WMI 呼叫時,將更多資訊傳送給提供者。 SWbemServices中的所有呼叫,以及SWbemObject中的某些呼叫,都會採用屬於此類型物件的選擇性參數。 用戶端可以將資訊新增至 SWbemNamedValueSet 物件,並使用呼叫作為其中一個參數來傳送 SWbemNamedValueSet 物件。 此物件可由 VBScript CreateObject 呼叫建立。

如需詳細資訊,請參閱 存取集合

注意

重要 - 可能的話,請勿使用此機制,因為它可以中斷 WMI 基礎的統一存取模型。 如果提供者確實使用此機制,請務必盡可能謹慎地使用此機制。 如果提供者需要大量高度特定的內容資訊來回應要求,則必須撰寫所有用戶端的程式碼,才能提供這項資訊。 此機制可讓您視需要存取這類提供者。

SWbemNamedValueSet物件是SWbemNamedValue專案的集合。 這些專案會使用 SWbemNamedValueSet.Add 方法新增至集合。 它們會使用 SWbemNamedValueSet.Remove 方法移除 ,並使用 SWbemNamedValueSet.Item 方法擷取。 您可以存取方法來填入動態提供者所需的任何內容資訊。 呼叫其中一個 SWbemServices 方法之後,您可以針對另一個呼叫重複使用 SWbemNamedValueSet 物件。

基礎提供者會決定 包含在 SWbemNamedValueSet 物件中的資訊。 WMI 不會使用資訊,但只會將它轉送到提供者。 提供者必須將所需的內容資訊發佈至服務要求。

成員

SWbemNamedValueSet物件具有下列類型的成員:

方法

SWbemNamedValueSet物件具有這些方法。

方法 描述
SWbemNamedValue 物件加入至集合。
複製 製作這個 SWbemNamedValueSet 集合的複本。
DeleteAll 從集合中移除所有專案,讓 SWbemNamedValueSet 物件成為空白。
項目 從集合擷取 SWbemNamedValue 物件。 這是 物件的預設方法。
移除 從集合中移除 SWbemNamedValue 物件。

屬性

SWbemNamedValueSet物件具有這些屬性。

屬性 存取類型 描述
Count
唯讀
集合中的項目數目

範例

下列 VBScript 範例示範具名值集的操作,在此情況下,具名值是陣列類型。

Set Context = CreateObject("WbemScripting.SWbemNamedValueSet")

On Error Resume Next

Context.Add "n1", Array (1, 2, 3)
str = "The initial value of n1 is {"
for x=LBound(Context("n1")) to UBound(Context("n1"))
 str = str & Context("n1")(x)
 if x <> UBound(Context("n1")) Then
  str = str & ", "
 End if
next
str = str & "}"
WScript.Echo str

WScript.Echo ""

' report the value of an element of the context value
v = Context("n1")
WScript.Echo "By indirection the first element of n1 has value:",v(0)

' report the value directly
WScript.Echo "By direct access the first element of n1 has value:", Context("n1")(0)

' set the value of a single named value element
Context("n1")(1) = 11 
WScript.Echo "After direct assignment the first element of n1 has value:", Context("n1")(1)

' set the value of a single named value element
Set v = Context("n1")
v(1) = 345
WScript.Echo "After indirect assignment the first element of n1 has value:", Context("n1")(1)

' set the value of an entire context value
Context("n1") = Array (5, 34, 178871)
WScript.Echo "After direct array assignment the first element of n1 has value:", Context("n1")(1)

str = "After direct assignment the entire value of n1 is {"
for x=LBound(Context("n1")) to UBound(Context("n1"))
 str = str & Context("n1")(x)
 if x <> UBound(Context("n1")) Then
  str = str & ", "
 End if
next
str = str & "}"
WScript.Echo str

if Err <> 0 Then
 WScript.Echo Err.Description
 Err.Clear
End if

下列 Perl 範例示範具名值集的操作,在具名值是陣列類型的情況下。

use strict;
use Win32::OLE;

my ( $Context, $str, $x, @v);

eval {$Context = new Win32::OLE 'WbemScripting.SWbemNamedValueSet'; };
unless($@)
{
 $Context->Add("n1", [1, 2, 3]);
 $str = "The initial value of n1 is {";
 for ($x = 0; $x < @{$Context->Item("n1")->{Value}}; $x++)
 {
  $str = $str.@{$Context->Item("n1")->{Value}}[$x];
  if ($x != (@{$Context->Item("n1")->{Value}}) - 1 )
  {
   $str = $str.", ";
  }
 }
 $str = $str."}";
 print $str,"\n\n";

 # report the value of an element of the context value
 @v = @{$Context->Item("n1")->{Value}};
 print "By indirection the first element of n1 has value:", $v[0], "\n";

 # report the value directly
 print "By direct access the first element of n1 has value:", @{$Context->Item("n1")->{Value}}[0], "\n";

 # set the value of a single named value element
 @{$Context->Item("n1")->{Value}}[1] = 11;
 print "After direct assignment the first element of n1 has value:", 
       @{$Context->Item("n1")->{Value}}[1], "\n";

 # set the value of a single named value element
 @v = @{$Context->Item("n1")->{Value}};
 $v[1] = 345;
 print "After indirect assignment the first element of n1 has value:", 
    @{$Context->Item("n1")->{Value}}[1], "\n";

 # set the value of an entire context value
 $Context->Item("n1")->{Value} = [5, 34, 178871];
 print "After direct array assignment the first element of n1 has value:", 
   @{$Context->Item("n1")->{Value}}[1], "\n";

 $str = "After direct assignment the entire value of n1 is {";
 for ($x = 0; $x < @{$Context->Item("n1")->{Value}}; $x++)
 {
  $str = $str.@{$Context->Item("n1")->{Value}}[$x];
  if ($x != (@{$Context->Item("n1")->{Value}}) - 1 )
  {
   $str = $str.", ";
  }
 }
 $str = $str."}";
 print $str,"\n";
}
else
{
 print STDERR Win32::OLE->LastError, "\n";
}

規格需求

需求
最低支援的用戶端
Windows Vista
最低支援的伺服器
Windows Server 2008
標頭
Wbemdisp.h
類型程式庫
Wbemdisp.tlb
DLL
Wbemdisp.dll
CLSID
CLSID_SWbemNamedValueSet
IID
IID_ISWbemNamedValueSet

另請參閱

編寫 API 物件的腳本