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.

151 lines
3.2 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 = "\\ALANBOS3\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. DumpSecurity (p.Security_)
  84. end Sub
  85. Sub DumpKeys (keys)
  86. for each key in keys
  87. WScript.Echo "KeyName:", key.Name, "KeyValue:", key.Value
  88. next
  89. end Sub
  90. Sub DumpSecurity (security)
  91. on error resume next
  92. impLevel = security.ImpersonationLevel
  93. if err <> 0 then
  94. WScript.Echo "Impersonation Level: <not set>"
  95. err.clear
  96. else
  97. WScript.Echo "Impersonation Level:", impLevel
  98. end if
  99. authLevel = security.AuthenticationLevel
  100. if err <> 0 then
  101. WScript.Echo "Authentication Level: <not set>"
  102. err.clear
  103. else
  104. WScript.Echo "Authentication Level:", authLevel
  105. end if
  106. DumpPrivileges (security.Privileges)
  107. end sub
  108. Sub DumpPrivileges (privileges)
  109. WScript.Echo "Privileges:"
  110. for each privilege in privileges
  111. WScript.Echo " ", Privilege.Name, Privilege.IsEnabled
  112. next
  113. end sub