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

44 lines
1.4 KiB
Plaintext

' Copyright (c) Microsoft Corporation, All Rights Reserved
'***************************************************************************
'
' WMI Sample Script - Reset to default (VBScript)
'
' This script illustrates how SWbemPropertySet.Remove can return
' wbemErrResetToDefault if the property is overridden.
'
'***************************************************************************
on error resume next
'Create a keyed class with a defaulted property
set service = GetObject("Winmgmts:")
set emptyclass = service.Get
emptyclass.path_.class = "REMOVETEST00"
set prop = emptyclass.properties_.add ("p", 19)
prop.qualifiers_.add "key", true
emptyclass.properties_.add ("q", 19).Value = 12
emptyclass.put_
'create an instance and override the property
set instance = service.get ("RemoveTest00").spawninstance_
instance.properties_("q").Value = 24
instance.properties_("p").Value = 1
instance.put_
'retrieve the instance and remove the property
set instance = service.get ("removetest00=1")
set property = instance.properties_ ("q")
WScript.echo "Overridden value of property is [24]:", property.value
WScript.echo ""
instance.properties_.remove "q"
set property = instance.properties_ ("q")
WScript.echo "Value of property after removal is [12]:", property.value
WScript.echo ""
if err <> 0 then
WScript.Echo "0x" & Hex(Err.Number), Err.Description, Err.Source
end if