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
6.6 KiB

  1. on error resume next
  2. Set Locator = CreateObject("WbemScripting.SWbemLocator")
  3. Set Service = Locator.ConnectServer
  4. WScript.Echo "Service initial settings:"
  5. WScript.Echo "Authentication: " & Service.Security_.AuthenticationLevel
  6. WScript.Echo "Impersonation: " & Service.Security_.ImpersonationLevel
  7. WScript.Echo ""
  8. Service.Security_.AuthenticationLevel = 2 'wbemAuthenticationLevelConnect
  9. Service.Security_.ImpersonationLevel = 3 'wbemImpersonationLevelImpersonate
  10. WScript.Echo "Service modified settings (expecting {2,3}):"
  11. WScript.Echo "Authentication: " & Service.Security_.AuthenticationLevel
  12. WScript.Echo "Impersonation: " & Service.Security_.ImpersonationLevel
  13. WScript.Echo ""
  14. 'Now get a class
  15. Set aClass = Service.Get("Win32_LogicalDisk")
  16. WScript.Echo "Class initial settings (expecting {2,3}):"
  17. WScript.Echo "Authentication: " & aClass.Security_.AuthenticationLevel
  18. WScript.Echo "Impersonation: " & aClass.Security_.ImpersonationLevel
  19. WScript.Echo ""
  20. aClass.Security_.AuthenticationLevel = 6 'wbemAuthenticationLevelPktPrivacy
  21. aClass.Security_.ImpersonationLevel = 2 'wbemImpersonationLevelIdentify
  22. WScript.Echo "Class modified settings (expecting {6,2}):"
  23. WScript.Echo "Authentication: " & aClass.Security_.AuthenticationLevel
  24. WScript.Echo "Impersonation: " & aClass.Security_.ImpersonationLevel
  25. WScript.Echo ""
  26. 'Now get an enumeration from the object
  27. Set Disks = aClass.Instances_
  28. WScript.Echo "Collection A initial settings (expecting {6,2}):"
  29. WScript.Echo "Authentication: " & Disks.Security_.AuthenticationLevel
  30. WScript.Echo "Impersonation: " & Disks.Security_.ImpersonationLevel
  31. WScript.Echo ""
  32. 'For grins print them out
  33. For Each Disk In Disks
  34. WScript.Echo Disk.Path_.DisplayName
  35. WScript.Echo Disk.Security_.AuthenticationLevel & ":" & Disk.Security_.ImpersonationLevel
  36. Next
  37. WScript.Echo ""
  38. Disks.Security_.AuthenticationLevel = 4 'wbemAuthenticationLevelPkt
  39. Disks.Security_.ImpersonationLevel = 1 'wbemImpersonationLevelAnonymous
  40. WScript.Echo "Collection A modified settings (expecting {4,1}):"
  41. WScript.Echo "Authentication: " & Disks.Security_.AuthenticationLevel
  42. WScript.Echo "Impersonation: " & Disks.Security_.ImpersonationLevel
  43. WScript.Echo ""
  44. 'Now get an enumeration from the service
  45. Set Services = Service.InstancesOf("Win32_service")
  46. WScript.Echo "Collection B initial settings (expecting {2,3}):"
  47. WScript.Echo "Authentication: " & Services.Security_.AuthenticationLevel
  48. WScript.Echo "Impersonation: " & Services.Security_.ImpersonationLevel
  49. WScript.Echo ""
  50. 'For grins print them out
  51. For Each MyService In Services
  52. WScript.Echo MyService.Path_.DisplayName
  53. WScript.Echo MyService.Security_.AuthenticationLevel & ":" & MyService.Security_.ImpersonationLevel
  54. Next
  55. WScript.Echo ""
  56. Services.Security_.AuthenticationLevel = 3 'wbemAuthenticationLevelCall
  57. Services.Security_.ImpersonationLevel = 4 'wbemImpersonationLevelDelegate
  58. WScript.Echo "Collection B modified settings (expecting {3,4} or {4,4}):"
  59. WScript.Echo "Authentication: " & Services.Security_.AuthenticationLevel
  60. WScript.Echo "Impersonation: " & Services.Security_.ImpersonationLevel
  61. WScript.Echo ""
  62. 'Print out again as settings should have changed
  63. For Each MyService In Services
  64. WScript.Echo MyService.Path_.DisplayName
  65. WScript.Echo MyService.Security_.AuthenticationLevel & ":" & MyService.Security_.ImpersonationLevel
  66. Next
  67. WScript.Echo ""
  68. 'Now get an event source
  69. Set Events = Service.ExecNotificationQuery _
  70. ("select * from __instancecreationevent where targetinstance isa 'Win32_NTLogEvent'")
  71. WScript.Echo "Event Source initial settings (expecting {2,3}):"
  72. WScript.Echo "Authentication: " & Events.Security_.AuthenticationLevel
  73. WScript.Echo "Impersonation: " & Events.Security_.ImpersonationLevel
  74. WScript.Echo ""
  75. Events.Security_.AuthenticationLevel = 5 'wbemAuthenticationLevelPktIntegrity
  76. Events.Security_.ImpersonationLevel = 4 'wbemImpersonationLevelDelegate
  77. WScript.Echo "Event Source modified settings (expecting {5,4}):"
  78. WScript.Echo "Authentication: " & Events.Security_.AuthenticationLevel
  79. WScript.Echo "Impersonation: " & Events.Security_.ImpersonationLevel
  80. WScript.Echo ""
  81. 'Now get an event
  82. 'WScript.Echo "Event settings (expecting {5,4}):"
  83. 'Set AnEventObject = Events.NextEvent
  84. 'WScript.Echo "Authentication: " & AnEventObject.Security_.AuthenticationLevel
  85. 'WScript.Echo "Impersonation: " & AnEventObject.Security_.ImpersonationLevel
  86. 'WScript.Echo ""
  87. 'Now generate an error from services
  88. Set Class2 = Service.Get("NoSuchClassss")
  89. If Err <> 0 Then
  90. Set MyError = CreateObject("WbemScripting.SWbemLastError")
  91. WScript.Echo "ERROR: " & Err.Description & "," & Err.Number & "," & Err.Source
  92. WScript.Echo "Error object initial settings (expecting {2,3}):"
  93. WScript.Echo "Authentication: " & MyError.Security_.AuthenticationLevel
  94. WScript.Echo "Impersonation: " & MyError.Security_.ImpersonationLevel
  95. WScript.Echo ""
  96. Err.Clear
  97. End If
  98. WScript.Echo "FINAL SETTINGS"
  99. WScript.Echo "=============="
  100. WScript.Echo ""
  101. WScript.Echo "Service settings (expected {2,3}) = {" & Service.Security_.AuthenticationLevel _
  102. & "," & Service.Security_.ImpersonationLevel & "}"
  103. WScript.Echo ""
  104. WScript.Echo "Class settings (expected {6,2}) = {" & aClass.Security_.AuthenticationLevel _
  105. & "," & aClass.Security_.ImpersonationLevel & "}"
  106. WScript.Echo ""
  107. WScript.Echo "Collection A settings (expected {4,1}) = {" & Disks.Security_.AuthenticationLevel _
  108. & "," & Disks.Security_.ImpersonationLevel & "}"
  109. WScript.Echo ""
  110. WScript.Echo "Collection B settings (expected {4,4} or {3,4}) = {" & Services.Security_.AuthenticationLevel _
  111. & "," & Services.Security_.ImpersonationLevel & "}"
  112. WScript.Echo ""
  113. WScript.Echo "Event Source settings (expected {5,4}) = {" & Events.Security_.AuthenticationLevel _
  114. & "," & Events.Security_.ImpersonationLevel & "}"
  115. If Err <> 0 Then
  116. WScript.Echo "ERROR: " & Err.Description & "," & Err.Number & "," & Err.Source
  117. End If
  118. WScript.Echo Services.Count & "+" & Disks.Count