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.

127 lines
2.7 KiB

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