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.

744 lines
19 KiB

  1. dim objISWbemLocator
  2. on error resume next
  3. '******************************************************************************
  4. '
  5. ' Main routine
  6. '
  7. '******************************************************************************
  8. WScript.Echo "Started"
  9. WScript.Echo ""
  10. errorSet = false
  11. TestLocator
  12. TestServices
  13. TestInstanceEnum1
  14. TestInstanceEnum2
  15. TestInstanceEnum3
  16. TestInstance1
  17. TestInstance2
  18. TestSelectQuery
  19. TestAssociationQuery
  20. TestObjectPath
  21. TestClassEnum
  22. TestProperties
  23. TestQualifiers
  24. TestMethods
  25. TestGetClass
  26. TestCreateClass
  27. TestCreateSubclass
  28. TestCreateInstance
  29. TestDeleteInstance
  30. TestDeleteSubclass
  31. TestDeleteClass
  32. TestNamedValueSet
  33. TestPrivilege
  34. if errorSet = true then
  35. WScript.Echo ""
  36. WScript.Echo ">>> BVT FAILED! <<<"
  37. WScript.Echo ""
  38. else
  39. WScript.Echo ""
  40. WScript.Echo ">>> BVT passed without errors <<<"
  41. WScript.Echo ""
  42. end if
  43. '******************************************************************************
  44. '
  45. ' TestLocator
  46. '
  47. '******************************************************************************
  48. Sub TestLocator
  49. on error resume next
  50. DisplayStep "TestLocator"
  51. Set objISWbemLocator = CreateObject("WbemScripting.SWbemLocator")
  52. if err.number <> 0 then
  53. ErrorString err, ""
  54. end if
  55. End Sub
  56. '******************************************************************************
  57. '
  58. ' TestServices
  59. '
  60. '******************************************************************************
  61. Sub TestServices
  62. on error resume next
  63. DisplayStep "TestServices"
  64. Set objISWbemServices = objISWbemLocator.ConnectServer("","root/cimv2")
  65. if err.number <> 0 then
  66. ErrorString err, ""
  67. end if
  68. End Sub
  69. '******************************************************************************
  70. '
  71. ' TestInstanceEnum1
  72. '
  73. '******************************************************************************
  74. Sub TestInstanceEnum1
  75. on error resume next
  76. DisplayStep "TestInstanceEnum1"
  77. for each Process in GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2").InstancesOf ("win32_process")
  78. Temp = Process.Name
  79. if err.number <> 0 then
  80. ErrorString err, "(within enumeration)"
  81. end if
  82. Next
  83. if err.number <> 0 then
  84. ErrorString err, "(end of enumeration)"
  85. end if
  86. End Sub
  87. '******************************************************************************
  88. '
  89. ' TestInstanceEnum2
  90. '
  91. '******************************************************************************
  92. Sub TestInstanceEnum2
  93. on error resume next
  94. DisplayStep "TestInstanceEnum2"
  95. for each Service in GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2:Win32_LogicalDisk").Instances_
  96. Temp = Service.Name
  97. if err.number <> 0 then
  98. ErrorString err, "(within enumeration)"
  99. end if
  100. Next
  101. if err.number <> 0 then
  102. ErrorString err, "(end of enumeration)"
  103. end if
  104. End Sub
  105. '******************************************************************************
  106. '
  107. ' TestInstanceEnum3
  108. '
  109. '******************************************************************************
  110. Sub TestInstanceEnum3
  111. on error resume next
  112. DisplayStep "TestInstanceEnum3"
  113. for each Disk in GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2").InstancesOf ("Win32_LogicalDisk")
  114. Temp = Disk.Name
  115. if err.number <> 0 then
  116. ErrorString err, "(within enumeration)"
  117. end if
  118. Next
  119. if err.number <> 0 then
  120. ErrorString err, "(end of enumeration)"
  121. end if
  122. End Sub
  123. '******************************************************************************
  124. '
  125. ' TestInstance1
  126. '
  127. '******************************************************************************
  128. Sub TestInstance1
  129. on error resume next
  130. DisplayStep "TestInstance1"
  131. Set objISWbemObject = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:__CIMOMIdentification=@")
  132. if err.number <> 0 then
  133. ErrorString err, "(getobject)"
  134. end if
  135. Temp = objISWbemObject.VersionCurrentlyRunning
  136. if err.number <> 0 then
  137. ErrorString err, "(property access)"
  138. end if
  139. End Sub
  140. '******************************************************************************
  141. '
  142. ' TestInstance2
  143. '
  144. '******************************************************************************
  145. Sub TestInstance2
  146. on error resume next
  147. DisplayStep "TestInstance2"
  148. Set objISWbemObject = GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2:Win32_LogicalDisk.DeviceID=""C:""")
  149. if err.number <> 0 then
  150. ErrorString err, "(getobject)"
  151. end if
  152. Temp = objISWbemObject.DeviceID
  153. if err.number <> 0 then
  154. ErrorString err, "(property access)"
  155. end if
  156. End Sub
  157. '******************************************************************************
  158. '
  159. ' TestSelectQuery
  160. '
  161. '******************************************************************************
  162. Sub TestSelectQuery
  163. on error resume next
  164. DisplayStep "TestSelectQuery"
  165. for each objISWbemObject in GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2").ExecQuery ("select * from Win32_Process where Name='notepad.exe'")
  166. Temp = objISWbemObject.Name
  167. if err.number <> 0 then
  168. ErrorString err, "(within enumeration)"
  169. end if
  170. Next
  171. if err.number <> 0 then
  172. ErrorString err, "(after enumeration)"
  173. end if
  174. End Sub
  175. '******************************************************************************
  176. '
  177. ' TestAssociationQuery
  178. '
  179. '******************************************************************************
  180. Sub TestAssociationQuery
  181. on error resume next
  182. DisplayStep "TestAssociationQuery"
  183. For Each objISWbemObject in GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2").ExecQuery ("Associators of {Win32_service.Name=""NetDDE""} Where AssocClass = Win32_DependentService Role = Dependent" )
  184. Temp = objISWbemObject.Name
  185. if err.number <> 0 then
  186. ErrorString err, "(within enumeration)"
  187. end if
  188. Next
  189. if err.number <> 0 then
  190. ErrorString err, "(after enumeration)"
  191. end if
  192. End Sub
  193. '******************************************************************************
  194. '
  195. ' TestObjectPath
  196. '
  197. '******************************************************************************
  198. Sub TestObjectPath
  199. on error resume next
  200. DisplayStep "TestObjectPath"
  201. Set objISWbemObject = _
  202. GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2:Win32_LogicalDisk.DeviceID=""C:""")
  203. if err.number <> 0 then
  204. ErrorString err, "get object)"
  205. end if
  206. ObjectPathAccess (objISWbemObject.Path_)
  207. DisplayStep "TestObjectPath[Creatable]"
  208. Set objISWbemObjectPath = CreateObject("WbemScripting.SWbemObjectPath")
  209. if err.number <> 0 then
  210. ErrorString err, "(create object)"
  211. end if
  212. objISWbemObjectPath.DisplayName = _
  213. "winmgmts:{impersonationLevel=delegate,(debug,security)}!//splodge/root/default:erewhon=10"
  214. ObjectPathAccess (objISWbemObjectPath)
  215. End Sub
  216. Sub ObjectPathAccess (objSWbemObjectPath)
  217. on error resume next
  218. Temp = objSWbemObjectPath.class
  219. if err.number <> 0 then
  220. ErrorString err, "Class property"
  221. end if
  222. Temp = objSWbemObjectPath.DisplayName
  223. if err.number <> 0 then
  224. ErrorString err, "DisplayName property"
  225. end if
  226. Temp = objSWbemObjectPath.Namespace
  227. if err.number <> 0 then
  228. ErrorString err, "Namespace property"
  229. end if
  230. Temp = objSWbemObjectPath.Path
  231. if err.number <> 0 then
  232. ErrorString err, "Path property"
  233. end if
  234. Temp = objSWbemObjectPath.RelPath
  235. if err.number <> 0 then
  236. ErrorString err, "RelPath property"
  237. end if
  238. Temp = objSWbemObjectPath.Server
  239. if err.number <> 0 then
  240. ErrorString err, "Server property"
  241. end if
  242. Temp = objSWbemObjectPath.ParentNamespace
  243. if err.number <> 0 then
  244. ErrorString err, "ParentNamespace property"
  245. end if
  246. Temp = objSWbemObjectPath.IsClass
  247. if err.number <> 0 then
  248. ErrorString err, "IsClass property"
  249. end if
  250. Temp = objSWbemObjectPath.IsSingleton
  251. if err.number <> 0 then
  252. ErrorString err, "IsSingleton property"
  253. end if
  254. for each Key in objSWbemObjectPath.Keys
  255. Temp = Key.Name
  256. Temp = Key.Value
  257. next
  258. if err.number <> 0 then
  259. ErrorString err, "Keys property"
  260. end if
  261. End Sub
  262. '******************************************************************************
  263. '
  264. ' TestClassEnum
  265. '
  266. '******************************************************************************
  267. Sub TestClassEnum
  268. on error resume next
  269. DisplayStep "TestClassEnum"
  270. for each objISWbemObject in GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2").SubClassesOf("Win32_Account")
  271. Set objSWbemObjectPath = objISWbemObject.Path_
  272. next
  273. if err.number <> 0 then
  274. ErrorString err, ""
  275. end if
  276. End Sub
  277. '******************************************************************************
  278. '
  279. ' TestProperties
  280. '
  281. '******************************************************************************
  282. Sub TestProperties
  283. on error resume next
  284. DisplayStep "TestProperties"
  285. Set objISWbemObject = _
  286. GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2:Win32_LogicalDisk.DeviceID=""C:""")
  287. if err.number <> 0 then
  288. ErrorString err, "(get object)"
  289. end if
  290. set objISWbemPropertySet = objISWbemObject.Properties_
  291. if err.number <> 0 then
  292. ErrorString err, "(get property set)"
  293. end if
  294. count = objISWbemPropertySet.Count
  295. if err.number <> 0 then
  296. ErrorString err, "(count)"
  297. end if
  298. for each objISWbemProperty in objISWbemPropertySet
  299. Temp = objISWbemProperty.name
  300. Temp = objISWbemProperty.value
  301. Temp = objISWbemProperty.CIMType
  302. Temp = objISWbemProperty.IsArray
  303. next
  304. if err.number <> 0 then
  305. ErrorString err, "(iterate)"
  306. end if
  307. End Sub
  308. '******************************************************************************
  309. '
  310. ' TestQualifiers
  311. '
  312. '******************************************************************************
  313. Sub TestQualifiers
  314. on error resume next
  315. DisplayStep "TestQualifiers"
  316. Set objISWbemObject = _
  317. GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2:Win32_LogicalDisk.DeviceID=""C:""")
  318. if err.number <> 0 then
  319. ErrorString err, "(get object)"
  320. end if
  321. set objISWbemQualifierSet = objISWbemObject.Qualifiers_
  322. if err.number <> 0 then
  323. ErrorString err, "(get collection)"
  324. end if
  325. count = objISWbemQualifierSet.Count
  326. if err.number <> 0 then
  327. ErrorString err, "(count)"
  328. end if
  329. for each objISWbemQualifier in objISWbemQualifierSet
  330. Temp = objISWbemQualifier.name
  331. Temp = objISWbemQualifier.value
  332. next
  333. if err.number <> 0 then
  334. ErrorString err, "(iterate)"
  335. end if
  336. End Sub
  337. '******************************************************************************
  338. '
  339. ' TestMethods
  340. '
  341. '******************************************************************************
  342. Sub TestMethods
  343. on error resume next
  344. DisplayStep "TestMethods"
  345. Set objISWbemObject = _
  346. GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2:Win32_LogicalDisk")
  347. if err.number <> 0 then
  348. ErrorString err, "(get)"
  349. end if
  350. set objISWbemMethodSet = objISWbemObject.Methods_
  351. if err.number <> 0 then
  352. ErrorString err, "(get collection)"
  353. end if
  354. if objISWbemMethodSet.count > 0 then
  355. for each objISWbemMethod in objISWbemMethodSet
  356. Temp = objISWbemMethod.name
  357. set Temp = objISWbemMethod.InParameters
  358. set Temp = objISWbemMethod.OutParameters
  359. next
  360. end if
  361. if err.number <> 0 then
  362. ErrorString err, "(iterate)"
  363. end if
  364. End Sub
  365. '******************************************************************************
  366. '
  367. ' TestGetClass
  368. '
  369. '******************************************************************************
  370. Sub TestGetClass
  371. on error resume next
  372. DisplayStep "TestGetClass"
  373. if err.number <> 0 then
  374. ErrorString err, "(service??)"
  375. end if
  376. Set objISWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate}!root/cimv2")
  377. if err.number <> 0 then
  378. ErrorString err, "(service)"
  379. end if
  380. Set objISWbemObject = objISWbemServices.Get("Win32_UserAccount")
  381. if err.number <> 0 then
  382. ErrorString err, "(get)"
  383. end if
  384. End Sub
  385. '******************************************************************************
  386. '
  387. ' TestCreateClass
  388. '
  389. '******************************************************************************
  390. Sub TestCreateClass
  391. on error resume next
  392. DisplayStep "TestCreateClass"
  393. set objISWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate}!root/default")
  394. if err.number <> 0 then
  395. ErrorString err, "(service)"
  396. end if
  397. Set objSWbemObject = objISWbemServices.Get("")
  398. if err.number <> 0 then
  399. ErrorString err, "(get)"
  400. end if
  401. objSWbemObject.Path_.Class = "Test_Class"
  402. if err.number <> 0 then
  403. ErrorString err, "(class)"
  404. end if
  405. set Property = objSWbemObject.Properties_.Add ("p1", 19)
  406. Property.Value = 12
  407. if err.number <> 0 then
  408. ErrorString err, "(add property)"
  409. end if
  410. Property.Qualifiers_.Add "key", true
  411. if err.number <> 0 then
  412. ErrorString err, "(add qualifier)"
  413. end if
  414. objSWbemObject.Put_
  415. if err.number <> 0 then
  416. ErrorString err, "(put)"
  417. end if
  418. End Sub
  419. '******************************************************************************
  420. '
  421. ' TestCreateSubClass
  422. '
  423. '******************************************************************************
  424. Sub TestCreateSubclass
  425. on error resume next
  426. DisplayStep "TestCreateSubclass"
  427. set objSWbemObject = _
  428. GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:Test_Class").SpawnDerivedClass_
  429. if err.number <> 0 then
  430. ErrorString err, "(spawn derived)"
  431. end if
  432. objSWbemObject.Path_.Class = "Test_SUBClass"
  433. if err.number <> 0 then
  434. ErrorString err, "(set path)"
  435. end if
  436. objSWbemObject.Put_
  437. if err.number <> 0 then
  438. ErrorString err, "(put)"
  439. end if
  440. End Sub
  441. '******************************************************************************
  442. '
  443. ' TestCreateInstance
  444. '
  445. '******************************************************************************
  446. Sub TestCreateInstance
  447. on error resume next
  448. DisplayStep "TestCreateInstance"
  449. set objSWbemObjectClass = _
  450. GetObject("winmgmts:{impersonationLevel=impersonate}!root/default:Test_Class")
  451. if err.number <> 0 then
  452. ErrorString err, "(get class)"
  453. end if
  454. set objSWbemObject = objSWbemObjectClass.SpawnInstance_
  455. if err.number <> 0 then
  456. ErrorString err, "(spawn)"
  457. end if
  458. objSWbemObject.p1 = 23
  459. if err.number <> 0 then
  460. ErrorString err, "(set key)"
  461. end if
  462. objSWbemObject.Put_
  463. if err.number <> 0 then
  464. ErrorString err, "(put)"
  465. end if
  466. End Sub
  467. '******************************************************************************
  468. '
  469. ' TestDeleteInstance
  470. '
  471. '******************************************************************************
  472. Sub TestDeleteInstance
  473. on error resume next
  474. DisplayStep "TestDeleteInstance"
  475. set objSWbemServices = _
  476. GetObject("winmgmts:{impersonationLevel=impersonate}!root/default")
  477. if err.number <> 0 then
  478. ErrorString err, "(service)"
  479. end if
  480. objSWbemServices.Delete ("Test_Class.p1=23")
  481. if err.number <> 0 then
  482. ErrorString err, "(delete)"
  483. end if
  484. End Sub
  485. '******************************************************************************
  486. '
  487. ' TestDeleteSubclass
  488. '
  489. '******************************************************************************
  490. Sub TestDeleteSubclass
  491. on error resume next
  492. DisplayStep "TestDeleteSubclass"
  493. set objSWbemServices = _
  494. GetObject("winmgmts:{impersonationLevel=impersonate}!root/default")
  495. if err.number <> 0 then
  496. ErrorString err, "(service)"
  497. end if
  498. objSWbemServices.Delete ("Test_SubClass")
  499. if err.number <> 0 then
  500. ErrorString err, "(delete)"
  501. end if
  502. End Sub
  503. '******************************************************************************
  504. '
  505. ' TestDeleteClass
  506. '
  507. '******************************************************************************
  508. Sub TestDeleteClass
  509. on error resume next
  510. DisplayStep "TestDeleteClass"
  511. set objSWbemServices = _
  512. GetObject("winmgmts:{impersonationLevel=impersonate}!root/default")
  513. if err.number <> 0 then
  514. ErrorString err, "(service)"
  515. end if
  516. objSWbemServices.Delete ("Test_Class")
  517. if err.number <> 0 then
  518. ErrorString err, "(delete)"
  519. end if
  520. End Sub
  521. '******************************************************************************
  522. '
  523. ' TestNamedValueSet
  524. '
  525. '******************************************************************************
  526. Sub TestNamedValueSet
  527. on error resume next
  528. DisplayStep "TestNamedValueSet"
  529. Set objSWbemNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
  530. if err.number <> 0 then
  531. ErrorString err, "(create object)"
  532. end if
  533. objSWbemNamedValueSet.Add "Hah", true
  534. objSWbemNamedValueSet.Add "Whoah", "Freddy the frog"
  535. objSWbemNamedValueSet.Add "Bam", Array(3456, 10, 12)
  536. if err.number <> 0 then
  537. ErrorString err, "(add elements)"
  538. end if
  539. objSWbemNamedValueSet.Remove "Hah"
  540. if err.number <> 0 then
  541. ErrorString err, "(remove elements)"
  542. end if
  543. set NVSet2 = objSWbemNamedValueSet.Clone
  544. if err.number <> 0 then
  545. ErrorString err, "(clone)"
  546. end if
  547. set objSWbemNamedValue = objSWbemNamedValueSet.Item ("Whoah")
  548. if err.number <> 0 then
  549. ErrorString err, "(extract)"
  550. end if
  551. for each namedValue in objSWbemNamedValueSet
  552. Temp = namedValue.Name
  553. Temp = namedValue.Value
  554. next
  555. if err.number <> 0 then
  556. ErrorString err, "(iterate)"
  557. end if
  558. End Sub
  559. '******************************************************************************
  560. '
  561. ' TestPrivilege
  562. '
  563. '******************************************************************************
  564. Sub TestPrivilege
  565. on error resume next
  566. DisplayStep "TestPrivilege"
  567. const wbemPrivilegeSecurity = 8
  568. set locator = CreateObject("WbemScripting.SWbemLocator")
  569. if err.number <> 0 then
  570. ErrorString err, "(locator)"
  571. end if
  572. locator.Security_.Privileges.Add wbemPrivilegeSecurity
  573. if err.number <> 0 then
  574. ErrorString err, "(add)"
  575. end if
  576. Set Privilege = locator.Security_.Privileges(wbemPrivilegeSecurity)
  577. Temp = Privilege.Name
  578. if err.number <> 0 then
  579. ErrorString err, "(get name)"
  580. end if
  581. locator.Security_.Privileges.AddAsString "SeDebugPrivilege"
  582. if err.number <> 0 then
  583. ErrorString err, "(add as string)"
  584. end if
  585. for each Privilege in locator.Security_.Privileges
  586. Temp = Privilege.DisplayName
  587. Temp = Privilege.Identifier
  588. Temp = Privilege.Name
  589. Temp = Privilege.IsEnabled
  590. next
  591. if err.number <> 0 then
  592. ErrorString err, "(iterate)"
  593. end if
  594. End Sub
  595. '***********************************************************************
  596. '*
  597. '* ErrorString
  598. '*
  599. '***********************************************************************
  600. sub ErrorString(theError,sMsg)
  601. on error resume next
  602. errorSet = true
  603. WScript.Echo " ERROR: [0x" & Hex(theError.Number) & " " & theError.Source & "] - " & theError.Description & " : " & sMsg
  604. 'Try and grab the last error object, if there is one
  605. Set objISWbemLastError = CreateObject("WbemScripting.SWbemLastError")
  606. if objISWbemLastError then
  607. WScript.Echo " last error " & objISWbemLastError.Description & " " & objISWbemLastError.operation & " " & objISWbemLastError.parameterinfo & " " & objISWbemLastError.providername & " " & objISWbemLastError.statuscode
  608. end if
  609. WScript.Quit (theError.number)
  610. End sub
  611. '***********************************************************************
  612. '*
  613. '* DisplayStep
  614. '*
  615. '***********************************************************************
  616. sub DisplayStep(step)
  617. on error resume next
  618. WScript.Echo "> " & step & " <"
  619. End sub