Leaked source code of windows server 2003
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

  1. <!--
  2. ******************************************************************
  3. '
  4. ' scrwinnt.wsf
  5. '
  6. ' Purpose: test UMI WinNT functionality
  7. '
  8. ' Parameters: none
  9. '
  10. ' Returns: 0 - success
  11. ' 1 - failure
  12. '
  13. '*****************************************************************
  14. -->
  15. <job id="UMI WinNT Test">
  16. <reference object="WbemScripting.SWbemLocator" version="1.2"/>
  17. <script language="VBScript">
  18. on error resume next
  19. set scriptHelper = CreateObject("WMIScriptHelper.WSC")
  20. scriptHelper.logFile = "c:\temp\umiwinnt.txt"
  21. scriptHelper.loggingLevel = 3
  22. scriptHelper.testName = "UMI WinNT"
  23. scriptHelper.testStart
  24. dim computerName
  25. computerName = "alanbos4"
  26. if WScript.arguments.Count > 0 then computerName = WScript.Arguments (0)
  27. TestBindings
  28. TestClasses
  29. TestAttributes
  30. TestSearch
  31. TestSecurity
  32. TestExtensions
  33. TestUsers
  34. TestGroups
  35. TestComputers
  36. scriptHelper.testComplete
  37. if scriptHelper.statusOK then
  38. WScript.Echo "PASS"
  39. WScript.Quit 0
  40. else
  41. WScript.Echo "FAIL"
  42. WScript.Quit 1
  43. end if
  44. '****************************************************************
  45. '*
  46. '* TestBindings
  47. '* ============
  48. '*
  49. '* Test of moniker-based binding to objects and explicit
  50. '* locator connections with search preferences.
  51. '*
  52. '****************************************************************
  53. Sub TestBindings ()
  54. on error resume next
  55. scriptHelper.writeToLog "", 2
  56. scriptHelper.writeToLog "**********************************", 2
  57. scriptHelper.writeToLog ">> Testing binding via monikers...", 2
  58. scriptHelper.writeToLog "**********************************", 2
  59. scriptHelper.writeToLog "", 2
  60. ' Bind to namespace using UMI path
  61. set conn = GetObject("umi:///winnt/computer=" & computerName)
  62. if err <> 0 then
  63. scriptHelper.writeErrorToLog err, "Failed to bind to umi:///winnt/computer=" & computerName
  64. else
  65. scriptHelper.writeToLog "Succesful binding to umi:///winnt/computer=" & computerName, 2
  66. end if
  67. 'Bind to single object using UMI path
  68. set user = GetObject("umi:///winnt/computer=" & computerName & "/user=guest")
  69. if err <> 0 then
  70. scriptHelper.writeErrorToLog err, "Failed to bind to umi:///winnt/computer=" & computerName & "/user=guest"
  71. else
  72. scriptHelper.writeToLog "Successful binding to umi:///winnt/computer=" & computerName & "/user=guest", 2
  73. end if
  74. ' Bind to single object using native path
  75. 'set user = GetObject("umiwinnt:///" & computerName & "/guest,User")
  76. 'if err <> 0 then
  77. ' scriptHelper.writeErrorToLog err, "Failed to bind to umiwinnt:///" & computerName & "/guest,User"
  78. 'else
  79. ' scriptHelper.writeToLog "Successful binding to umiwinnt:///" & computerName & "/guest,User", 2
  80. 'end if
  81. ' Bind using a umi server path
  82. ' Bind using a native server path
  83. ' Bind using connection properties
  84. ' set locator = CreateObject("WbemScripting.SWbemLocatorEx")
  85. ' set context = CreateObject("WbemScripting.SWbemNamedValueSet")
  86. ' context.Add
  87. End Sub
  88. '****************************************************************
  89. '*
  90. '* TestClasses
  91. '* ===========
  92. '*
  93. '* Test of class manipulation.
  94. '*
  95. '****************************************************************
  96. Sub TestClasses ()
  97. on error resume next
  98. scriptHelper.writeToLog "", 2
  99. scriptHelper.writeToLog "**********************************", 2
  100. scriptHelper.writeToLog ">> Testing classes...", 2
  101. scriptHelper.writeToLog "**********************************", 2
  102. scriptHelper.writeToLog "", 2
  103. ' Bind to namespace using UMI path
  104. set conn = GetObject("umi:///winnt/computer=" & computerName)
  105. if err <> 0 then
  106. scriptHelper.writeErrorToLog err, "Failed to bind to umi:///winnt/computer=" & computerName
  107. else
  108. scriptHelper.writeToLog "Succesful binding to umi:///winnt/computer=" & computerName, 2
  109. end if
  110. for each c in conn.SubclassesOf
  111. if err <> 0 then
  112. scriptHelper.writeErrorToLog err, "Failed to get class"
  113. else
  114. DisplayClass c
  115. DisplayInstances conn, c.Path_.Class
  116. end if
  117. next
  118. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate classes"
  119. End Sub
  120. '****************************************************************
  121. '*
  122. '* TestAttributes
  123. '* ==============
  124. '*
  125. '* Test of attribute manipulation.
  126. '*
  127. '****************************************************************
  128. Sub TestAttributes ()
  129. on error resume next
  130. scriptHelper.writeToLog "", 2
  131. scriptHelper.writeToLog "**********************************", 2
  132. scriptHelper.writeToLog ">> Testing attributes...", 2
  133. scriptHelper.writeToLog "**********************************", 2
  134. scriptHelper.writeToLog "", 2
  135. set conn = GetObject("umi:///winnt/computer=" & computerName)
  136. set user = conn.Get("user=guest")
  137. scriptHelper.writeToLog "Getting a user", 2
  138. if err <> 0 then
  139. scriptHelper.writeErrorToLog err, "Failed to get user"
  140. else
  141. scriptHelper.writeToLog "Succesfully retrieved user", 2
  142. end if
  143. ' Attribute enumeration
  144. set props = user.Properties_
  145. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
  146. DisplayProperties props
  147. ' Single attribute retrieval by name
  148. value = user.Description
  149. if err <> 0 then
  150. scriptHelper.writeErrorToLog err, "Failed to get user.Description"
  151. else
  152. scriptHelper.writeToLog "User description is <" & value & ">", 2
  153. end if
  154. ' System properties
  155. set props = user.SystemProperties_
  156. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get system properties"
  157. DisplayProperties props
  158. ' Attribute modification
  159. user.Description = user.Description & " foo"
  160. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to set user.Description"
  161. user.Put_
  162. if err <> 0 then
  163. scriptHelper.writeErrorToLog err, "Failed to put user"
  164. else
  165. scriptHelper.writeToLog "User put successfuly", 2
  166. end if
  167. ' Casting attributes to multivalues
  168. ' Object-valued attributes
  169. ' Multivalued attribute modification
  170. ' Refreshing the cache
  171. user.Refresh_
  172. if err <> 0 then
  173. scriptHelper.writeErrorToLog err, "Failed to refresh user"
  174. else
  175. scriptHelper.writeToLog "User refreshed successfuly: " & user.Description, 2
  176. end if
  177. ' Refreshing specific items in the cache
  178. user.Description = "blah"
  179. user.FullName = "Zarniwoop"
  180. user.Refresh_ Array("Description", "PrimaryGroupID")
  181. if err <> 0 then
  182. scriptHelper.writeErrorToLog err, "Failed to refresh specific user properties"
  183. else
  184. scriptHelper.writeToLog "Specific user properties refreshed successfuly: " & user.Description & " : " & user.FullName, 2
  185. end if
  186. ' Property Count
  187. count = user.Properties_.Count
  188. if err <> 0 then
  189. scriptHelper.writeErrorToLog err, "Failed to count properties"
  190. else
  191. scriptHelper.writeToLog "Number of properties is: " & count, 2
  192. end if
  193. ' Schemaless attributes
  194. ' Parent traversal
  195. parent = user.Path_.Parent
  196. if err <> 0 then
  197. scriptHelper.writeErrorToLog err, "Failed to get parent"
  198. else
  199. scriptHelper.writeToLog "Parent is : " & parent, 2
  200. end if
  201. set parentObject = GetObject(parent)
  202. if err <> 0 then
  203. scriptHelper.writeErrorToLog err, "Failed to open parent"
  204. else
  205. scriptHelper.writeToLog "Parent opened OK", 2
  206. end if
  207. End Sub
  208. '****************************************************************
  209. '*
  210. '* TestSearch
  211. '* ==========
  212. '*
  213. '* Test of queries
  214. '*
  215. '****************************************************************
  216. Sub TestSearch ()
  217. on error resume next
  218. scriptHelper.writeToLog "", 2
  219. scriptHelper.writeToLog "**********************************", 2
  220. scriptHelper.writeToLog ">> Testing Search...", 2
  221. scriptHelper.writeToLog "**********************************", 2
  222. scriptHelper.writeToLog "", 2
  223. 'Search preferences
  224. 'Search result traversal
  225. End Sub
  226. '****************************************************************
  227. '*
  228. '* TestSecurity
  229. '* ============
  230. '*
  231. '* Test of security
  232. '*
  233. '****************************************************************
  234. Sub TestSecurity ()
  235. on error resume next
  236. scriptHelper.writeToLog "", 2
  237. scriptHelper.writeToLog "**********************************", 2
  238. scriptHelper.writeToLog ">> Testing Security...", 2
  239. scriptHelper.writeToLog "**********************************", 2
  240. scriptHelper.writeToLog "", 2
  241. 'Get SD with flags
  242. 'Display ACLs and ACEs
  243. 'Change something
  244. 'Commit
  245. End Sub
  246. '****************************************************************
  247. '*
  248. '* TestExtensions
  249. '* ==============
  250. '*
  251. '* Test of extension interfaces
  252. '*
  253. '****************************************************************
  254. Sub TestExtensions ()
  255. on error resume next
  256. scriptHelper.writeToLog "", 2
  257. scriptHelper.writeToLog "**********************************", 2
  258. scriptHelper.writeToLog ">> Testing Extensions...", 2
  259. scriptHelper.writeToLog "**********************************", 2
  260. scriptHelper.writeToLog "", 2
  261. 'Late-bound property access
  262. End Sub
  263. '****************************************************************
  264. '*
  265. '* TestUsers
  266. '* =========
  267. '*
  268. '* Test of users
  269. '*
  270. '****************************************************************
  271. Sub TestUsers ()
  272. on error resume next
  273. scriptHelper.writeToLog "", 2
  274. scriptHelper.writeToLog "**********************************", 2
  275. scriptHelper.writeToLog ">> Testing Users...", 2
  276. scriptHelper.writeToLog "**********************************", 2
  277. scriptHelper.writeToLog "", 2
  278. 'Listing users on a computer
  279. 'Listing users in a domain
  280. 'Adding a user
  281. 'Setting a user password
  282. 'Setting user flags
  283. 'Moving a user
  284. 'Renaming a user
  285. 'Copying a user
  286. End Sub
  287. '****************************************************************
  288. '*
  289. '* TestGroups
  290. '* ==========
  291. '*
  292. '* Test of groups
  293. '*
  294. '****************************************************************
  295. Sub TestGroups ()
  296. on error resume next
  297. scriptHelper.writeToLog "", 2
  298. scriptHelper.writeToLog "**********************************", 2
  299. scriptHelper.writeToLog ">> Testing Groups...", 2
  300. scriptHelper.writeToLog "**********************************", 2
  301. scriptHelper.writeToLog "", 2
  302. 'Listing groups on a computer
  303. 'Listing groups in a domain
  304. 'Listing members of a group
  305. 'Adding a user to a group
  306. 'Removing a user from a group
  307. End Sub
  308. '****************************************************************
  309. '*
  310. '* TestComputers
  311. '* =============
  312. '*
  313. '* Test of computers
  314. '*
  315. '****************************************************************
  316. Sub TestComputers ()
  317. on error resume next
  318. scriptHelper.writeToLog "", 2
  319. scriptHelper.writeToLog "**********************************", 2
  320. scriptHelper.writeToLog ">> Testing Computers...", 2
  321. scriptHelper.writeToLog "**********************************", 2
  322. scriptHelper.writeToLog "", 2
  323. 'Listing computers in a domain
  324. 'Creating a computer account
  325. 'Deleting a computer account
  326. End Sub
  327. '****************************************************************
  328. '*
  329. '* StrFromCIMType
  330. '* ==============
  331. '*
  332. '* Utility function to return string form of CIM type
  333. '*
  334. '****************************************************************
  335. function StrFromCIMType (cimType)
  336. on error resume next
  337. StrFromCIMType = "?"
  338. Select Case cimType
  339. Case wbemCimtypeString StrFromCIMType = "String"
  340. Case wbemCimtypeIllegal StrFromCIMType = "Illegal"
  341. Case wbemCimtypeSint8 StrFromCIMType = "Sint8"
  342. Case wbemCimtypeUint8 StrFromCIMType = "Uint8"
  343. Case wbemCimtypeSint16 StrFromCIMType = "Sint16"
  344. Case wbemCimtypeUint16 StrFromCIMType = "Uint16"
  345. Case wbemCimtypeSint32 StrFromCIMType = "Sint32"
  346. Case wbemCimtypeUint32 StrFromCIMType = "Uint32"
  347. Case wbemCimtypeSint64 StrFromCIMType = "Sint64"
  348. Case wbemCimtypeUint64 StrFromCIMType = "Uint64"
  349. Case wbemCimtypeReal32 StrFromCIMType = "Real32"
  350. Case wbemCimtypeReal64 StrFromCIMType = "Real64"
  351. Case wbemCimtypeBoolean StrFromCIMType = "Boolean"
  352. Case wbemCimtypeDatetime StrFromCIMType = "Datetime"
  353. Case wbemCimtypeReference StrFromCIMType = "Reference"
  354. Case wbemCimtypeChar16 StrFromCIMType = "Cha16"
  355. Case wbemCimtypeObject StrFromCIMType = "Object"
  356. Case wbemCimtypeIUnknown StrFromCIMType = "IUnknown"
  357. End Select
  358. end function
  359. Sub DisplayClass (c)
  360. on error resume next
  361. scriptHelper.writeToLog "", 2
  362. scriptHelper.writeToLog "***************************", 2
  363. className = c.Path_.Class
  364. if err <> 0 then
  365. scriptHelper.writeErrorToLog err, "Failed to get classname"
  366. else
  367. scriptHelper.writeToLog "Class:" & className, 2
  368. end if
  369. superclassName = c.Derivation_(0)
  370. if err <> 0 then
  371. scriptHelper.writeErrorToLog err, "Failed to get superclass"
  372. else
  373. scriptHelper.writeToLog "Superclass:" & superclassName, 2
  374. end if
  375. ' Properties
  376. set props = c.Properties_
  377. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
  378. DisplayProperties props
  379. scriptHelper.writeToLog "***************************", 2
  380. scriptHelper.writeToLog "", 2
  381. End Sub
  382. Sub DisplayInstance (i)
  383. on error resume next
  384. scriptHelper.writeToLog "", 2
  385. scriptHelper.writeToLog "***************************", 2
  386. path = i.SystemProperties_("__URL")
  387. if err <> 0 then
  388. scriptHelper.writeErrorToLog err, "Failed to get path"
  389. else
  390. scriptHelper.writeToLog "Path:" & className, 2
  391. end if
  392. nativepath = i.SystemProperties_("__PATH")
  393. if err <> 0 then
  394. scriptHelper.writeErrorToLog err, "Failed to get native path"
  395. else
  396. scriptHelper.writeToLog "Native Path:" & nativepath, 2
  397. end if
  398. ' Properties
  399. set props = i.Properties_
  400. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to get properties"
  401. DisplayProperties props
  402. scriptHelper.writeToLog "***************************", 2
  403. scriptHelper.writeToLog "", 2
  404. End Sub
  405. Sub DisplayProperties (props)
  406. on error resume next
  407. for each p in props
  408. if err <> 0 then
  409. scriptHelper.writeErrorToLog err, "Failed to get property"
  410. else
  411. dim value
  412. if p.IsArray then
  413. value = "{"
  414. v = p.Value
  415. for i = LBound(v) to UBound(v)
  416. if IsObject(v(i)) then
  417. value = value & "<object>"
  418. else
  419. value = value & v(i)
  420. end if
  421. if i <> UBound(v) then value = value & ","
  422. next
  423. value = value & "}"
  424. else
  425. value = p.Value
  426. end if
  427. scriptHelper.writeToLog " " & p.Name & "[" & StrFromCIMType(p.CIMType) & "]: " & value, 2
  428. end if
  429. next
  430. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate properties"
  431. End Sub
  432. '****************************************************************
  433. '*
  434. '* DisplayInstances
  435. '* ================
  436. '*
  437. '* Enumerate and display instances
  438. '*
  439. '****************************************************************
  440. Sub DisplayInstances (conn,className)
  441. on error resume next
  442. scriptHelper.writeToLog "", 2
  443. scriptHelper.writeToLog "**********************************", 2
  444. scriptHelper.writeToLog ">> Testing instances...", 2
  445. scriptHelper.writeToLog "**********************************", 2
  446. scriptHelper.writeToLog "", 2
  447. for each i in conn.InstancesOf (className)
  448. if err <> 0 then
  449. scriptHelper.writeErrorToLog err, "Failed to get instance"
  450. else
  451. DisplayInstance i
  452. end if
  453. next
  454. if err <> 0 then scriptHelper.writeErrorToLog err, "Failed to enumerate instances"
  455. End Sub
  456. </script>
  457. </job>