You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
560 lines
13 KiB
560 lines
13 KiB
<!--
|
|
******************************************************************
|
|
'
|
|
' objpath.wsf
|
|
'
|
|
' Purpose: test SWbemObjectPath
|
|
'
|
|
' Parameters: none
|
|
'
|
|
' Returns: 0 - success
|
|
' 1 - failure
|
|
'
|
|
'*****************************************************************
|
|
-->
|
|
|
|
<job id="WMI ObjectPath Test">
|
|
<reference object="WbemScripting.SWbemLocator" version="1.2"/>
|
|
<script language="VBScript">
|
|
|
|
on error resume next
|
|
|
|
set scriptHelper = CreateObject("WMIScriptHelper.WSC")
|
|
scriptHelper.logFile = "c:\temp\objpath.txt"
|
|
scriptHelper.loggingLevel = 3
|
|
scriptHelper.testName = "WMI ObjectPath"
|
|
scriptHelper.testStart
|
|
|
|
dim path
|
|
|
|
TestPreamble
|
|
TestServer
|
|
TestNamespace
|
|
TestClass
|
|
TestIsClass
|
|
TestRelPath
|
|
TestKeys
|
|
TestSecurity
|
|
TestLocale
|
|
TestAuthority
|
|
TestPath
|
|
TestDisplayName
|
|
TestComponents
|
|
TestParent
|
|
TestSecurityDescriptor
|
|
|
|
scriptHelper.testComplete
|
|
|
|
if scriptHelper.statusOK then
|
|
WScript.Echo "PASS"
|
|
WScript.Quit 0
|
|
else
|
|
WScript.Echo "FAIL"
|
|
WScript.Quit 1
|
|
end if
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestPreamble
|
|
'* ============
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestPreamble
|
|
|
|
on error resume next
|
|
|
|
' Try to create a new path object
|
|
set path = CreateObject("WbemScripting.SWbemObjectPath")
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to create SWbemObjectPath"
|
|
else
|
|
scriptHelper.writeToLog "Successful creation of SWbemObjectPath", 2
|
|
end if
|
|
|
|
' Check the typename
|
|
if typename(path) = "SWbemObjectPathEx" then
|
|
scriptHelper.writeToLog "Object has correct type", 2
|
|
else
|
|
scriptHelper.writeErrorToLog , "Object has incorrect type:", typename(path)
|
|
end if
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestServer
|
|
'* ==========
|
|
'*
|
|
'* Test Server component
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestServer
|
|
|
|
on error resume next
|
|
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog ">> TestServer", 2
|
|
|
|
' What is the default value of the server
|
|
server = path.Server
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get Server"
|
|
elseif server <> "" then
|
|
scriptHelper.writeErrorToLog err, "Unexpected server value"
|
|
else
|
|
scriptHelper.writeToLog "Successful retrieval of Server", 2
|
|
end if
|
|
|
|
' Try and set it
|
|
path.Server = "erewhon"
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to set Server"
|
|
elseif path.Server <> "erewhon" then
|
|
scriptHelper.writeErrorToLog err, "Unexpected server value"
|
|
else
|
|
scriptHelper.writeToLog "Successful set of Server:[" & path.Server & "]", 2
|
|
end if
|
|
|
|
scriptHelper.writeToLog "<< TestServer", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestNamespace
|
|
'* =============
|
|
'*
|
|
'* Test Namespace component
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestNamespace
|
|
|
|
on error resume next
|
|
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog ">> TestNamespace", 2
|
|
|
|
' What is the default value of the namespace
|
|
namespace = path.Namespace
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get Namespace"
|
|
elseif namespace <> "" then
|
|
scriptHelper.writeErrorToLog err, "Unexpected namespace value"
|
|
else
|
|
scriptHelper.writeToLog "Successful retrieval of Namespace", 2
|
|
end if
|
|
|
|
' Try and set it
|
|
path.Namespace = "root\cimv2"
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to set Namespace"
|
|
elseif path.Namespace <> "root\cimv2" then
|
|
scriptHelper.writeErrorToLog err, "Unexpected namespace value"
|
|
else
|
|
scriptHelper.writeToLog "Successful set of Namespace:[" & path.Namespace & "]", 2
|
|
end if
|
|
|
|
scriptHelper.writeToLog "<< TestNamespace", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestClass
|
|
'* =========
|
|
'*
|
|
'* Test Class component
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestClass
|
|
|
|
on error resume next
|
|
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog ">> TestClass", 2
|
|
|
|
' What is the default value of the class
|
|
sClass = path.Class
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get Class"
|
|
elseif sClass <> "" then
|
|
scriptHelper.writeErrorToLog err, "Unexpected class value"
|
|
else
|
|
scriptHelper.writeToLog "Successful retrieval of Class", 2
|
|
end if
|
|
|
|
' Try and set it
|
|
path.Class = "rocco"
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to set Class"
|
|
elseif path.Class <> "rocco" then
|
|
scriptHelper.writeErrorToLog err, "Unexpected Class value"
|
|
else
|
|
scriptHelper.writeToLog "Successful set of Class:[" & path.Class & "]", 2
|
|
end if
|
|
|
|
scriptHelper.writeToLog "<< TestClass", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestIsClass
|
|
'* ============
|
|
'*
|
|
'* Test SetIsClass component
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestIsClass
|
|
|
|
on error resume next
|
|
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog ">> TestIsClass", 2
|
|
|
|
' Set an non-class path
|
|
path.Path = "\\flatland\root\shapes"
|
|
|
|
if Not(path.IsClass) then
|
|
scriptHelper.writeToLog "Non-Class successfully detected", 2
|
|
else
|
|
scriptHelper.writeErrorToLog err, "Unexpected IsClass value"
|
|
end if
|
|
|
|
' Set the class value
|
|
path.Class = "orphee"
|
|
|
|
if path.IsClass then
|
|
scriptHelper.writeToLog "Class successfully detected", 2
|
|
else
|
|
scriptHelper.writeErrorToLog err, "Unexpected IsClass value"
|
|
end if
|
|
|
|
' Try and set as a singleton
|
|
path.SetAsSingleton
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to set as singleton"
|
|
elseif path.IsClass then
|
|
scriptHelper.writeErrorToLog , "Incorrectly marked as class"
|
|
elseif Not(path.IsSingleton) then
|
|
scriptHelper.writeErrorToLog , "Incorrectly marked as not a singleton"
|
|
elseif path.Relpath <> "orphee=@" then
|
|
scriptHelper.writeErrorToLog err, "Unexpected relpath value"
|
|
else
|
|
scriptHelper.writeToLog "Successful set as singleton:[" & path.Path & "]", 2
|
|
end if
|
|
|
|
' Set back to a class
|
|
path.SetAsClass
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to set as class"
|
|
elseif Not(path.IsClass) then
|
|
scriptHelper.writeErrorToLog , "Incorrectly marked as not a class"
|
|
elseif path.IsSingleton then
|
|
scriptHelper.writeErrorToLog , "Incorrectly marked as a singleton"
|
|
elseif path.Relpath <> "orphee" then
|
|
scriptHelper.writeErrorToLog err, "Unexpected relpath value"
|
|
else
|
|
scriptHelper.writeToLog "Successful set as class:[" & path.Path & "]", 2
|
|
end if
|
|
|
|
' Set as an instance
|
|
path.RelPath = "orphee=1"
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to set relpath"
|
|
elseif path.IsClass then
|
|
scriptHelper.writeErrorToLog , "Incorrectly marked as a class"
|
|
elseif path.IsSingleton then
|
|
scriptHelper.writeErrorToLog , "Incorrectly marked as a singleton"
|
|
elseif path.Relpath <> "orphee=1" then
|
|
scriptHelper.writeErrorToLog err, "Unexpected relpath value :[" & path.Relpath & "]"
|
|
else
|
|
scriptHelper.writeToLog "Successful set as instance:[" & path.Path & "]", 2
|
|
end if
|
|
|
|
scriptHelper.writeToLog "<< TestIsClass", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestKeys
|
|
'* ========
|
|
'*
|
|
'* Test SetKeys component
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestKeys
|
|
|
|
on error resume next
|
|
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog ">> TestKeys", 2
|
|
|
|
path.Path = "\\.\root\default:orphee"
|
|
|
|
' What is the default value of the keys
|
|
set keys = path.Keys
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get Keys"
|
|
elseif Keys.Count <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Unexpected keys"
|
|
else
|
|
scriptHelper.writeToLog "Successful retrieval of keys", 2
|
|
end if
|
|
|
|
' Set as an instance
|
|
path.Path = "\\.\root\default:orphee.Name='Jean'"
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to set relpath"
|
|
elseif path.Keys.Count <> 1 then
|
|
scriptHelper.writeErrorToLog , "Incorrect number of keys: [" & path.Keys.Count & "] " & path.RelPath
|
|
elseif path.Keys("Name") <> "Jean" then
|
|
scriptHelper.writeErrorToLog , "Incorrect key value"
|
|
else
|
|
scriptHelper.writeToLog "Successful set of keys", 2
|
|
end if
|
|
|
|
' Add a key
|
|
path.Keys.Add "Surname", "Cocteau"
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to add keys"
|
|
elseif path.Keys.Count <> 2 then
|
|
scriptHelper.writeErrorToLog , "Incorrect number of keys: [" & path.Keys.Count & "] " & path.RelPath
|
|
elseif path.Keys("Surname") <> "Cocteau" then
|
|
scriptHelper.writeErrorToLog , "Incorrect key value"
|
|
else
|
|
scriptHelper.writeToLog "Successful add of keys", 2
|
|
end if
|
|
|
|
' Remove a key
|
|
path.Keys.Remove "Name"
|
|
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to remove keys"
|
|
elseif path.Keys.Count <> 1 then
|
|
scriptHelper.writeErrorToLog , "Incorrect number of keys: [" & path.Keys.Count & "] " & path.RelPath
|
|
elseif path.Keys("Surname") <> "Cocteau" then
|
|
scriptHelper.writeErrorToLog , "Incorrect key value"
|
|
else
|
|
scriptHelper.writeToLog "Successful remove of keys", 2
|
|
end if
|
|
|
|
scriptHelper.writeToLog "<< TestKeys", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestRelpath
|
|
'* ===========
|
|
'*
|
|
'* Test Relpath component
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestRelPath
|
|
|
|
on error resume next
|
|
|
|
scriptHelper.writeToLog ">> TestRelpath", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
' reset the path
|
|
path.Path = ""
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to clear path"
|
|
else
|
|
scriptHelper.writeToLog "Successful clear of path", 2
|
|
end if
|
|
|
|
' What is the default value of the keys
|
|
relpath = path.RelPath
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get RelPath"
|
|
elseif RelPath <> "" then
|
|
scriptHelper.writeErrorToLog , "Unexpected RelPath"
|
|
else
|
|
scriptHelper.writeToLog "Successful retrieval of RelPath", 2
|
|
end if
|
|
|
|
' Try and set it
|
|
path.RelPath = "orphee.Name=11"
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to set Relpath"
|
|
elseif path.RelPath <> "orphee.Name=11" then
|
|
scriptHelper.writeErrorToLog , "Unexpected RelPath value:[" & path.RelPath & "]"
|
|
else
|
|
scriptHelper.writeToLog "Successful set of RelPath:[" & path.RelPath & "]", 2
|
|
end if
|
|
|
|
scriptHelper.writeToLog "<< TestRelpath", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestPath
|
|
'* ========
|
|
'*
|
|
'* Test Path component
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestPath
|
|
|
|
on error resume next
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestDisplayName
|
|
'* ===============
|
|
'*
|
|
'* Test DisplayName component
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestDisplayName
|
|
|
|
on error resume next
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestSingleton
|
|
'* =============
|
|
'*
|
|
'* Test Singleton
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestSingleton
|
|
|
|
on error resume next
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestSecurity
|
|
'* ============
|
|
'*
|
|
'* Test Security
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestSecurity
|
|
|
|
on error resume next
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestLocale
|
|
'* ==========
|
|
'*
|
|
'* Test Locale
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestLocale
|
|
|
|
on error resume next
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestAuthority
|
|
'* ==========
|
|
'*
|
|
'* Test Authority
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestAuthority
|
|
|
|
on error resume next
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestComponents
|
|
'* ==============
|
|
'*
|
|
'* Test Components
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestComponents
|
|
|
|
on error resume next
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestParent
|
|
'* ==========
|
|
'*
|
|
'* Test Parent
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestParent
|
|
|
|
on error resume next
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestSecurityDescriptor
|
|
'* ======================
|
|
'*
|
|
'* Test SD
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestSecurityDescriptor
|
|
|
|
on error resume next
|
|
|
|
End Sub
|
|
|
|
</script>
|
|
</job>
|