2025-11-28 00:35:46 +09:00

60 lines
1.8 KiB
Plaintext

' Copyright (c) Microsoft Corporation, All Rights Reserved
'***************************************************************************
'
' WMI Sample Script - Named value set array manipulation (VBScript)
'
' This script demonstrates the manipulation of named value sets, in the case
' that the named value is an array type.
'
'***************************************************************************
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