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.
574 lines
15 KiB
574 lines
15 KiB
<!--
|
|
******************************************************************
|
|
'
|
|
' scrwinnt.wsf
|
|
'
|
|
' Purpose: test UMI WinNT functionality
|
|
'
|
|
' Parameters: none
|
|
'
|
|
' Returns: 0 - success
|
|
' 1 - failure
|
|
'
|
|
'*****************************************************************
|
|
-->
|
|
|
|
<job id="UMI WinNT Test">
|
|
<reference object="WbemScripting.SWbemLocator" version="1.2"/>
|
|
<script language="VBScript">
|
|
|
|
on error resume next
|
|
|
|
set scriptHelper = CreateObject("WMIScriptHelper.WSC")
|
|
scriptHelper.logFile = "c:\temp\umiwinnt.txt"
|
|
scriptHelper.loggingLevel = 3
|
|
scriptHelper.testName = "UMI WinNT"
|
|
scriptHelper.testStart
|
|
|
|
dim computerName
|
|
computerName = "alanbos4"
|
|
|
|
if WScript.arguments.Count > 0 then computerName = WScript.Arguments (0)
|
|
|
|
TestBindings
|
|
TestClasses
|
|
TestAttributes
|
|
TestSearch
|
|
TestSecurity
|
|
TestExtensions
|
|
TestUsers
|
|
TestGroups
|
|
TestComputers
|
|
|
|
scriptHelper.testComplete
|
|
|
|
if scriptHelper.statusOK then
|
|
WScript.Echo "PASS"
|
|
WScript.Quit 0
|
|
else
|
|
WScript.Echo "FAIL"
|
|
WScript.Quit 1
|
|
end if
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestBindings
|
|
'* ============
|
|
'*
|
|
'* Test of moniker-based binding to objects and explicit
|
|
'* locator connections with search preferences.
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestBindings ()
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog ">> Testing binding via monikers...", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
' Bind to namespace using UMI path
|
|
set conn = GetObject("umi:///winnt/computer=" & computerName)
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to bind to umi:///winnt/computer=" & computerName
|
|
else
|
|
scriptHelper.writeToLog "Succesful binding to umi:///winnt/computer=" & computerName, 2
|
|
end if
|
|
|
|
'Bind to single object using UMI path
|
|
set user = GetObject("umi:///winnt/computer=" & computerName & "/user=guest")
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to bind to umi:///winnt/computer=" & computerName & "/user=guest"
|
|
else
|
|
scriptHelper.writeToLog "Successful binding to umi:///winnt/computer=" & computerName & "/user=guest", 2
|
|
end if
|
|
|
|
' Bind to single object using native path
|
|
'set user = GetObject("umiwinnt:///" & computerName & "/guest,User")
|
|
'if err <> 0 then
|
|
' scriptHelper.writeErrorToLog err, "Failed to bind to umiwinnt:///" & computerName & "/guest,User"
|
|
'else
|
|
' scriptHelper.writeToLog "Successful binding to umiwinnt:///" & computerName & "/guest,User", 2
|
|
'end if
|
|
|
|
' Bind using a umi server path
|
|
|
|
' Bind using a native server path
|
|
|
|
' Bind using connection properties
|
|
' set locator = CreateObject("WbemScripting.SWbemLocatorEx")
|
|
' set context = CreateObject("WbemScripting.SWbemNamedValueSet")
|
|
' context.Add
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestClasses
|
|
'* ===========
|
|
'*
|
|
'* Test of class manipulation.
|
|
'*
|
|
'****************************************************************
|
|
Sub TestClasses ()
|
|
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog ">> Testing classes...", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
' Bind to namespace using UMI path
|
|
set conn = GetObject("umi:///winnt/computer=" & computerName)
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to bind to umi:///winnt/computer=" & computerName
|
|
else
|
|
scriptHelper.writeToLog "Succesful binding to umi:///winnt/computer=" & computerName, 2
|
|
end if
|
|
|
|
for each c in conn.SubclassesOf
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get class"
|
|
else
|
|
DisplayClass c
|
|
DisplayInstances conn, c.Path_.Class
|
|
end if
|
|
next
|
|
|
|
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate classes"
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestAttributes
|
|
'* ==============
|
|
'*
|
|
'* Test of attribute manipulation.
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestAttributes ()
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog ">> Testing attributes...", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
set conn = GetObject("umi:///winnt/computer=" & computerName)
|
|
set user = conn.Get("user=guest")
|
|
scriptHelper.writeToLog "Getting a user", 2
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get user"
|
|
else
|
|
scriptHelper.writeToLog "Succesfully retrieved user", 2
|
|
end if
|
|
|
|
' Attribute enumeration
|
|
set props = user.Properties_
|
|
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
|
|
|
|
DisplayProperties props
|
|
|
|
' Single attribute retrieval by name
|
|
value = user.Description
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get user.Description"
|
|
else
|
|
scriptHelper.writeToLog "User description is <" & value & ">", 2
|
|
end if
|
|
|
|
' System properties
|
|
set props = user.SystemProperties_
|
|
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get system properties"
|
|
|
|
DisplayProperties props
|
|
|
|
' Attribute modification
|
|
user.Description = user.Description & " foo"
|
|
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to set user.Description"
|
|
|
|
user.Put_
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to put user"
|
|
else
|
|
scriptHelper.writeToLog "User put successfuly", 2
|
|
end if
|
|
|
|
' Casting attributes to multivalues
|
|
|
|
' Object-valued attributes
|
|
|
|
' Multivalued attribute modification
|
|
|
|
' Refreshing the cache
|
|
user.Refresh_
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to refresh user"
|
|
else
|
|
scriptHelper.writeToLog "User refreshed successfuly: " & user.Description, 2
|
|
end if
|
|
|
|
' Refreshing specific items in the cache
|
|
user.Description = "blah"
|
|
user.FullName = "Zarniwoop"
|
|
user.Refresh_ Array("Description", "PrimaryGroupID")
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to refresh specific user properties"
|
|
else
|
|
scriptHelper.writeToLog "Specific user properties refreshed successfuly: " & user.Description & " : " & user.FullName, 2
|
|
end if
|
|
|
|
' Property Count
|
|
count = user.Properties_.Count
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to count properties"
|
|
else
|
|
scriptHelper.writeToLog "Number of properties is: " & count, 2
|
|
end if
|
|
|
|
' Schemaless attributes
|
|
|
|
' Parent traversal
|
|
parent = user.Path_.Parent
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get parent"
|
|
else
|
|
scriptHelper.writeToLog "Parent is : " & parent, 2
|
|
end if
|
|
|
|
set parentObject = GetObject(parent)
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to open parent"
|
|
else
|
|
scriptHelper.writeToLog "Parent opened OK", 2
|
|
end if
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestSearch
|
|
'* ==========
|
|
'*
|
|
'* Test of queries
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestSearch ()
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog ">> Testing Search...", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
'Search preferences
|
|
|
|
'Search result traversal
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestSecurity
|
|
'* ============
|
|
'*
|
|
'* Test of security
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestSecurity ()
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog ">> Testing Security...", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
'Get SD with flags
|
|
|
|
'Display ACLs and ACEs
|
|
|
|
'Change something
|
|
|
|
'Commit
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestExtensions
|
|
'* ==============
|
|
'*
|
|
'* Test of extension interfaces
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestExtensions ()
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog ">> Testing Extensions...", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
'Late-bound property access
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestUsers
|
|
'* =========
|
|
'*
|
|
'* Test of users
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestUsers ()
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog ">> Testing Users...", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
'Listing users on a computer
|
|
|
|
'Listing users in a domain
|
|
|
|
'Adding a user
|
|
|
|
'Setting a user password
|
|
|
|
'Setting user flags
|
|
|
|
'Moving a user
|
|
|
|
'Renaming a user
|
|
|
|
'Copying a user
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestGroups
|
|
'* ==========
|
|
'*
|
|
'* Test of groups
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestGroups ()
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog ">> Testing Groups...", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
'Listing groups on a computer
|
|
|
|
'Listing groups in a domain
|
|
|
|
'Listing members of a group
|
|
|
|
'Adding a user to a group
|
|
|
|
'Removing a user from a group
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* TestComputers
|
|
'* =============
|
|
'*
|
|
'* Test of computers
|
|
'*
|
|
'****************************************************************
|
|
|
|
Sub TestComputers ()
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog ">> Testing Computers...", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
'Listing computers in a domain
|
|
|
|
'Creating a computer account
|
|
|
|
'Deleting a computer account
|
|
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* StrFromCIMType
|
|
'* ==============
|
|
'*
|
|
'* Utility function to return string form of CIM type
|
|
'*
|
|
'****************************************************************
|
|
|
|
function StrFromCIMType (cimType)
|
|
on error resume next
|
|
StrFromCIMType = "?"
|
|
Select Case cimType
|
|
Case wbemCimtypeString StrFromCIMType = "String"
|
|
Case wbemCimtypeIllegal StrFromCIMType = "Illegal"
|
|
Case wbemCimtypeSint8 StrFromCIMType = "Sint8"
|
|
Case wbemCimtypeUint8 StrFromCIMType = "Uint8"
|
|
Case wbemCimtypeSint16 StrFromCIMType = "Sint16"
|
|
Case wbemCimtypeUint16 StrFromCIMType = "Uint16"
|
|
Case wbemCimtypeSint32 StrFromCIMType = "Sint32"
|
|
Case wbemCimtypeUint32 StrFromCIMType = "Uint32"
|
|
Case wbemCimtypeSint64 StrFromCIMType = "Sint64"
|
|
Case wbemCimtypeUint64 StrFromCIMType = "Uint64"
|
|
Case wbemCimtypeReal32 StrFromCIMType = "Real32"
|
|
Case wbemCimtypeReal64 StrFromCIMType = "Real64"
|
|
Case wbemCimtypeBoolean StrFromCIMType = "Boolean"
|
|
Case wbemCimtypeDatetime StrFromCIMType = "Datetime"
|
|
Case wbemCimtypeReference StrFromCIMType = "Reference"
|
|
Case wbemCimtypeChar16 StrFromCIMType = "Cha16"
|
|
Case wbemCimtypeObject StrFromCIMType = "Object"
|
|
Case wbemCimtypeIUnknown StrFromCIMType = "IUnknown"
|
|
End Select
|
|
end function
|
|
|
|
Sub DisplayClass (c)
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "***************************", 2
|
|
|
|
className = c.Path_.Class
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get classname"
|
|
else
|
|
scriptHelper.writeToLog "Class:" & className, 2
|
|
end if
|
|
|
|
superclassName = c.Derivation_(0)
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get superclass"
|
|
else
|
|
scriptHelper.writeToLog "Superclass:" & superclassName, 2
|
|
end if
|
|
|
|
' Properties
|
|
set props = c.Properties_
|
|
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
|
|
|
|
DisplayProperties props
|
|
|
|
scriptHelper.writeToLog "***************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
|
|
End Sub
|
|
|
|
Sub DisplayInstance (i)
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "***************************", 2
|
|
|
|
path = i.SystemProperties_("__URL")
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get path"
|
|
else
|
|
scriptHelper.writeToLog "Path:" & className, 2
|
|
end if
|
|
|
|
nativepath = i.SystemProperties_("__PATH")
|
|
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get native path"
|
|
else
|
|
scriptHelper.writeToLog "Native Path:" & nativepath, 2
|
|
end if
|
|
|
|
' Properties
|
|
set props = i.Properties_
|
|
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
|
|
|
|
DisplayProperties props
|
|
|
|
scriptHelper.writeToLog "***************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
|
|
End Sub
|
|
|
|
Sub DisplayProperties (props)
|
|
on error resume next
|
|
|
|
for each p in props
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get property"
|
|
else
|
|
dim value
|
|
|
|
if p.IsArray then
|
|
value = "{"
|
|
v = p.Value
|
|
|
|
for i = LBound(v) to UBound(v)
|
|
if IsObject(v(i)) then
|
|
value = value & "<object>"
|
|
else
|
|
value = value & v(i)
|
|
end if
|
|
|
|
if i <> UBound(v) then value = value & ","
|
|
next
|
|
|
|
value = value & "}"
|
|
else
|
|
value = p.Value
|
|
end if
|
|
|
|
scriptHelper.writeToLog " " & p.Name & "[" & StrFromCIMType(p.CIMType) & "]: " & value, 2
|
|
end if
|
|
next
|
|
|
|
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate properties"
|
|
End Sub
|
|
|
|
'****************************************************************
|
|
'*
|
|
'* DisplayInstances
|
|
'* ================
|
|
'*
|
|
'* Enumerate and display instances
|
|
'*
|
|
'****************************************************************
|
|
Sub DisplayInstances (conn,className)
|
|
|
|
on error resume next
|
|
scriptHelper.writeToLog "", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog ">> Testing instances...", 2
|
|
scriptHelper.writeToLog "**********************************", 2
|
|
scriptHelper.writeToLog "", 2
|
|
|
|
for each i in conn.InstancesOf (className)
|
|
if err <> 0 then
|
|
scriptHelper.writeErrorToLog err, "Failed to get instance"
|
|
else
|
|
DisplayInstance i
|
|
end if
|
|
next
|
|
|
|
if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate instances"
|
|
|
|
End Sub
|
|
|
|
|
|
</script>
|
|
</job>
|