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.

115 lines
2.5 KiB

  1. On Error Resume Next
  2. while true
  3. WScript.Echo ""
  4. WScript.Echo "Create an Object Path"
  5. WScript.Echo ""
  6. Set d = CreateObject("WbemScripting.SWbemObjectPath")
  7. d.Path = "\\ALANBOS3\ROOT\DEFAULT:Foo.Bar=12,Wibble=""Hah"""
  8. DumpPath(d)
  9. d.RelPath = "Hmm.G=1,H=3"
  10. WScript.Echo ""
  11. DumpPath(d)
  12. Set d = Nothing
  13. WScript.Echo ""
  14. WScript.Echo "Extract an Object Path from a class"
  15. WScript.Echo ""
  16. Set c = GetObject("winmgmts:").Get
  17. c.Path_.Class = "PATHTEST00"
  18. Set p = c.Put_
  19. DumpPath(p)
  20. WScript.Echo ""
  21. WScript.Echo "Extract an Object Path from a singleton"
  22. WScript.Echo ""
  23. Set i = GetObject("winmgmts:root/default:__cimomidentification=@")
  24. Set p = i.Path_
  25. DumpPath(p)
  26. WScript.Echo ""
  27. WScript.Echo "Extract an Object Path from a keyed instance"
  28. WScript.Echo ""
  29. Set i = GetObject("winmgmts:{impersonationLevel=Impersonate}!win32_logicaldisk=""C:""")
  30. Set p = i.Path_
  31. DumpPath(p)
  32. if Err <> 0 then
  33. WScript.Echo ""
  34. WScript.Echo "!Error:", Err.Number, Err.Description
  35. End if
  36. 'try to modify this path - should get an error
  37. WScript.Echo ""
  38. WScript.Echo "Attempt illegal modification of object path class"
  39. WScript.Echo ""
  40. p.Class = "WHoops"
  41. if Err <> 0 then
  42. WScript.Echo "Trapped error successfully:", Err.Number, Err.Source, Err.Description
  43. Err.Clear
  44. else
  45. WScript.Echo "FAILED to trap error"
  46. end if
  47. WScript.Echo ""
  48. WScript.Echo "Attempt illegal modification of object path keys"
  49. WScript.Echo ""
  50. p.Keys.Remove ("DeviceID")
  51. if Err <> 0 then
  52. WScript.Echo "Trapped error successfully:", Err.Number, Err.Source, Err.Description
  53. Err.Clear
  54. else
  55. WScript.Echo "FAILED to trap error"
  56. end if
  57. WScript.Echo ""
  58. WScript.Echo "Clone keys"
  59. WScript.Echo ""
  60. Set newKeys = p.Keys.Clone
  61. DumpKeys (newKeys)
  62. WScript.Echo ""
  63. WScript.Echo "Change Cloned keys"
  64. WScript.Echo ""
  65. 'Note that the cloned copy of Keys _should_ be mutable
  66. newKeys.Add "fred", 23
  67. newKeys.Remove "DeviceID"
  68. DumpKeys (newKeys)
  69. Sub DumpPath(p)
  70. WScript.Echo "Path=", p.Path
  71. WScript.Echo "RelPath=",p.RelPath
  72. WScript.Echo "Class=", p.Class
  73. WScript.Echo "Server=", p.Server
  74. WScript.Echo "Namespace=", p.Namespace
  75. WScript.Echo "DisplayName=", p.DisplayName
  76. WScript.Echo "ParentNamespace=", p.ParentNamespace
  77. WScript.Echo "IsClass=", p.IsClass
  78. WScript.Echo "IsSingleton=", p.IsSingleton
  79. DumpKeys (p.Keys)
  80. end Sub
  81. Sub DumpKeys (keys)
  82. for each key in keys
  83. WScript.Echo "KeyName:", key.Name, "KeyValue:", key.Value
  84. next
  85. end Sub
  86. wend