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.

377 lines
12 KiB

  1. <HTML>
  2. <HEAD>
  3. <TITLE> Monitor
  4. </TITLE>
  5. <SCRIPT LANGUAGE="VBSCRIPT">
  6. CONST CONST_REBOOT_FORCE = 6
  7. CONST CONST_REBOOT_NOFORCE = 2
  8. Dim theService
  9. Dim theEventsService
  10. Dim theLocator
  11. Dim theEventsWindow
  12. Dim theCDSink
  13. Dim theCPUSink
  14. Dim theBoxSink
  15. Dim memoryInfo
  16. Dim cpuInfo
  17. Dim cdromInfo
  18. Dim diskInfo
  19. Dim MyMapiSession
  20. ' Initialize Globals
  21. Sub window_onLoad()
  22. memoryInfo = ""
  23. cpuInfo = ""
  24. cdromInfo = ""
  25. diskInfo = ""
  26. 'Set MyMapiSession = CreateObject("MSMAPI.MAPISession")
  27. 'MyMapiSession.SignOn
  28. set theCDSink = CreateObject("WbemScripting.SWbemSink")
  29. set theCPUSink = CreateObject("WbemScripting.SWbemSink")
  30. set theBoxSink = CreateObject("WbemScripting.SWbemSink")
  31. alert("Done init")
  32. End Sub
  33. Sub SoundAlarm
  34. ' Start a couple of services
  35. Set theLocalService = theLocator.ConnectServer
  36. theLocalService.Security_.impersonationLevel = 3
  37. Dim classObject
  38. Set classObject = theLocalService.Get ( "Win32_Process" )
  39. Dim intProcessId
  40. Dim intStatus
  41. intStatus = classObject.Create("c:\winnt\system32\wbem\sound.exe", null, null, intProcessId)
  42. End Sub
  43. Sub RebootMachine
  44. theEventsWindow.value = theEventsWindow.value & "Reboot Machine Called"
  45. On Error Resume Next
  46. for each machine in theService.InstancesOf ("Win32_OperatingSystem")
  47. theEventsWindow.value = theEventsWindow.value & "Trying reboot on " & machine.Path_path
  48. machine.Win32ShutDown 6
  49. If Err <> 0 Then
  50. theEventsWindow.value = "CreateObject Error : " & Err.Description
  51. End if
  52. next
  53. End Sub
  54. Sub Sendmail ( Subject , Message )
  55. '
  56. ' Send a mail message using mapi
  57. '
  58. Dim mapiMessages
  59. Set mapiMessages = CreateObject("MSMAPI.MAPIMessages")
  60. mapiMessages.SessionID = MyMapiSession.SessionID
  61. mapiMessages.Compose
  62. mapiMessages.RecipDisplayName = "Steve Menzies"
  63. mapiMessages.RecipAddress = "stevm"
  64. mapiMessages.AddressResolveUI = True
  65. mapiMessages.ResolveName
  66. mapiMessages.MsgSubject = Subject
  67. mapiMessages.MsgNoteText = Message
  68. mapiMessages.Send False
  69. ' MyMapiSession.SignOff
  70. End Sub
  71. '
  72. ' Gets machine info and starts monitoring
  73. '
  74. Sub GetMachineInfo()
  75. On Error Resume Next
  76. ' Set globals
  77. Set theEventsWindow = Document.all("EventsWindow")
  78. theEventsWindow.value = "EventsWindow"
  79. ' Create the Locator
  80. Set theLocator = CreateObject("WbemScripting.SWbemLocator")
  81. If Err <> 0 Then
  82. theEventsWindow.value = "CreateObject Error : " & Err.Description
  83. End if
  84. ' Start a couple of services
  85. Set theService = theLocator.ConnectServer( Machine.Value, "root\cimv2", "redmond\stevm", "wmidemo_2000")
  86. If Err <> 0 Then
  87. theEventsWindow.value = theEventsWindow.value & "ConnectServer Error : " & Err.Description
  88. End if
  89. theService.Security_.impersonationLevel = 3
  90. Set theEventsService = theLocator.ConnectServer( Machine.value, "root\cimv2", "redmond\stevm", "wmidemo_2000")
  91. If Err <> 0 Then
  92. theEventsWindow.value = theEventsWindow.value & "ConnectServer for events service Error : " & Err.Description
  93. End if
  94. theEventsService.Security_.impersonationLevel = 3
  95. ' Get the information
  96. 'GetCPUInfo
  97. 'GetMemoryInfo
  98. 'GetDiskInfo
  99. 'GetCDROMInfo
  100. StartMonitoring
  101. End Sub
  102. Sub ShowCD
  103. On Error Resume Next
  104. Dim theImage
  105. Set theImage = document.all("theCDROM")
  106. theImage.height = 200
  107. theImage.width = 200
  108. End Sub
  109. Sub HideCD
  110. On Error Resume Next
  111. Dim theImage
  112. Set theImage = document.all("theCDROM")
  113. theImage.height = 0
  114. theImage.width = 0
  115. End Sub
  116. Sub OpenBox
  117. On Error Resume Next
  118. Dim theImage
  119. Set theImage = document.all("theBoard")
  120. theImage.src = "mboardCool.jpg"
  121. Sendmail "Machine Opened!", "The box of the machine outsoft9.dns.microsoft.com has been opened!"
  122. SoundAlarm
  123. End Sub
  124. Sub CloseBox
  125. On Error Resume Next
  126. Dim theImage
  127. Set theImage = document.all("theBoard")
  128. theImage.src = "computer.jpg"
  129. Sendmail "Machine Closed!" , "The box of the machine outsoft9.dns.microsoft.com has been closed!"
  130. End Sub
  131. Sub MakeCold
  132. On Error Resume Next
  133. Dim theImage
  134. Set theImage = document.all("theBoard")
  135. theImage.src = "mboardCool.jpg"
  136. Sendmail "Machine temperature back to normal!", "The motherboard of the machine outsoft9.dns.microsoft.com has returned to normal temperature!"
  137. End Sub
  138. Sub MakeHotter
  139. On Error Resume Next
  140. Dim theImage
  141. Set theImage = document.all("theBoard")
  142. theImage.src = "mboardHot.jpg"
  143. End Sub
  144. Sub MakeHottest
  145. On Error Resume Next
  146. Dim theImage
  147. Set theImage = document.all("theBoard")
  148. theImage.src = "mboardHottest.jpg"
  149. Sendmail "Machine temperature at ABNORMAL level!", "The motherboard of the machine outsoft9.dns.microsoft.com has gone beyond the threshold of 35 Degrees Centigrade!"
  150. SoundAlarm
  151. End Sub
  152. '
  153. ' Gets information about the processors
  154. '
  155. Sub GetCPUInfo()
  156. On Error Resume Next
  157. cpuInfo = ""
  158. i = 0
  159. for each Processor in theService.InstancesOf ("Win32_Processor")
  160. cpuInfo = cpuInfo & Chr(13) & Processor.Name & " Revision: " & Processor.Revision
  161. cpuInfo = cpuInfo & Chr(13) & "DeviceID: " & Processor.DeviceID
  162. cpuInfo = cpuInfo & Chr(13) & "Description: " & Processor.Description
  163. cpuInfo = cpuInfo & Chr(13) & "AddressWidth: " & Processor.AddressWidth
  164. cpuInfo = cpuInfo & Chr(13) & "DataWidth: " & Processor.DataWidth
  165. cpuInfo = cpuInfo & Chr(13) & "CurrentClockSpeed: " & Processor.CurrentClockSpeed
  166. i = i+1
  167. next
  168. cpuInfo = "Number of Processors = " & i & cpuInfo
  169. End Sub
  170. '
  171. ' Gets information about the memory
  172. '
  173. Sub GetMemoryInfo()
  174. memoryInfo = ""
  175. On Error Resume Next
  176. i = 0
  177. for each Mem in theService.InstancesOf ("win32_logicalMemoryConfiguration")
  178. memoryInfo = memoryInfo & "Total Physical Memory: " & Mem.TotalPhysicalMemory & " Kilo Bytes"
  179. i = i+1
  180. next
  181. End Sub
  182. '
  183. ' Gets information about the cdrom drive
  184. '
  185. Sub GetCDROMInfo()
  186. On Error Resume Next
  187. cdromInfo = ""
  188. i = 0
  189. for each Drive in theService.InstancesOf ("Win32_CDRomDrive")
  190. cdromInfo = cdromInfo & Chr(13) & "DeviceID: " & Drive.DeviceID
  191. cdromInfo = cdromInfo & Chr(13) & "Description: " & Drive.Description
  192. cdromInfo = cdromInfo & Chr(13) & "Caption: " & Drive.Caption
  193. cdromInfo = cdromInfo & Chr(13) & "MediaType: " & Drive.MediaType
  194. cdromInfo = cdromInfo & Chr(13) & "Manufacturer: " & Drive.Manufacturer
  195. cdromInfo = cdromInfo & Chr(13) & "MediaLoaded: " & Drive.MediaLoaded
  196. if Drive.MediaLoaded then
  197. ShowCD
  198. cdromInfo = cdromInfo & Chr(13) & "VolumeName: " & Drive.VolumeName
  199. end if
  200. i = i + 1
  201. next
  202. cdromInfo = "Number of CDROM drives = " & i & cdromInfo
  203. End Sub
  204. '
  205. ' Gets information about the disks
  206. '
  207. Sub GetDiskInfo()
  208. On Error Resume Next
  209. diskInfo = ""
  210. i = 0
  211. for each Drive in theService.InstancesOf ("Win32_DiskDrive")
  212. diskInfo = diskInfo & Chr(13) & "DeviceID: " & Drive.DeviceID
  213. diskInfo = diskInfo & Chr(13) & "Description: " & Drive.Description
  214. diskInfo = diskInfo & Chr(13) & "Caption: " & Drive.Caption
  215. diskInfo = diskInfo & Chr(13) & "Size: " & Drive.Size
  216. diskInfo = diskInfo & Chr(13) & "BytesPerSector: " & Drive.BytesPerSector
  217. diskInfo = diskInfo & Chr(13) & "SectorsPerTrack: " & Drive.SectorsPerTrack
  218. diskInfo = diskInfo & Chr(13) & "InterfaceType: " & Drive.InterfaceType
  219. diskInfo = diskInfo & Chr(13) & "MediaType: " & Drive.MediaType
  220. diskInfo = diskInfo & Chr(13) & "Manufacturer: " & Drive.Manufacturer
  221. diskInfo = diskInfo & Chr(13) & "Number of partitions: " & Drive.Partitions
  222. diskInfo = diskInfo & Chr(13) & "TotalCylinders: " & Drive.TotalCylinders
  223. diskInfo = diskInfo & Chr(13) & "TotalHeads: " & Drive.TotalHeads
  224. diskInfo = diskInfo & Chr(13) & "TotalHeads: " & Drive.TotalHeads
  225. diskInfo = diskInfo & Chr(13) & "TracksPerCylinder: " & Drive.TracksPerCylinder
  226. i = i+1
  227. next
  228. diskInfo = "Number of Disks = " & i & diskInfo
  229. End Sub
  230. Sub StartMonitoring()
  231. On Error Resume Next
  232. If Err <> 0 Then
  233. theEventsWindow.Value = theEventsWindow.Value & "CreateObject WBEMSink Error : " & Err.Description
  234. End if
  235. ' Start the CD Monitor
  236. theEventsService.ExecNotificationQueryAsync theCDSink, _
  237. "select * from __instanceModificationEvent within 1 where targetinstance isa 'win32_cdromDrive'"
  238. If Err <> 0 Then
  239. theEventsWindow.Value = theEventsWindow.Value & "ExecQuery CDROM Drive Error : " & Err.Description
  240. End if
  241. End Sub
  242. Sub ShowInfo(theNum)
  243. Select Case theNum
  244. Case 1
  245. MsgBox memoryInfo,,"Physical Memory Details"
  246. Case 2
  247. MsgBox diskInfo,,"Physical Disk Details"
  248. Case 3
  249. MsgBox cpuInfo,,"Processor Details"
  250. Case 4
  251. MsgBox cdromInfo,,"CDROM Drive Details"
  252. End Select
  253. End Sub
  254. </SCRIPT>
  255. <SCRIPT FOR="theCDSink" EVENT="OnObjectReady(objObject, objAsyncContext)" LANGUAGE="VBScript">
  256. ' theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: " & objObject.Path_.RelPath
  257. Set theChangedObject = objObject.Properties_("TargetInstance")
  258. If theChangedObject.Value.Properties_("MediaLoaded") = TRUE Then
  259. theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: Showing CD"
  260. ShowCD
  261. Else
  262. theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: Hiding CD"
  263. HideCD
  264. End If
  265. </SCRIPT>
  266. <SCRIPT FOR="theBoxSink" EVENT="OnObjectReady(objObject, objAsyncContext)" LANGUAGE="VBScript">
  267. ' theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: " & objObject.Path_.RelPath
  268. If objObject.Properties_("EventDescription") = 2 Then
  269. theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: Opening Box"
  270. OpenBox
  271. Else
  272. theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: ClosingBox"
  273. CloseBox
  274. End If
  275. </SCRIPT>
  276. <SCRIPT FOR="theCPUSink" EVENT="OnObjectReady(objObject, objAsyncContext)" LANGUAGE="VBScript">
  277. 'theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: " & objObject.Properties_("EventDescription")
  278. If objObject.Properties_("EventDescription") = 2 Then
  279. theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: Heatin up"
  280. MakeHottest
  281. Else
  282. theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: Cooling Down"
  283. MakeCold
  284. End If
  285. </SCRIPT>
  286. </HEAD>
  287. <BODY>
  288. <LABEL FOR="Machine" ID="MachineLabel">MACHINE</LABEL>
  289. <INPUT TYPE="text" NAME="Machine" ID="Machine"
  290. SIZE=20
  291. TITLE="The machine from which to get the hardware information">
  292. </INPUT>
  293. <BUTTON NAME="MachineInfo" ID="MachineInfo" onClick=GetMachineInfo>Get Data</BUTTON>
  294. <BUTTON NAME="RebootButton" ID="RebootButton" onClick=RebootMachine>Shutdown Remote Machine</BUTTON>
  295. <TEXTAREA ID="EventsWindow" ROWS=5 COLS=55>
  296. </TEXTAREA>
  297. <DIV>
  298. <IMG ID="theBoard" SRC="computer.jpg" USEMAP="#theMap" BORDER=0 WIDTH=450 HEIGHT=450>
  299. </IMG>
  300. <MAP NAME="theMap" ID="theMap">
  301. <AREA SHAPE=RECT ONCLICK="showInfo(1)" TITLE="Click Here to get Memory Information" COORDS="8,113,100,415">
  302. <AREA SHAPE=RECT ONCLICK="showInfo(2)" TITLE="Click Here to get Disk Drive Information" COORDS="217,8,415,150">
  303. <AREA SHAPE=RECT ONCLICK="showInfo(3)" TITLE="Click Here to get Processor Information" COORDS="100,113,213,415">
  304. <AREA SHAPE=RECT ONCLICK="showInfo(4)" TITLE="Click Here to get CD ROM Information" COORDS="217,155,415,415">
  305. </MAP>
  306. <IMG ID="theCDROM" NAME=theCDROM SRC="cdrom.jpg" BORDER=0 WIDTH=0 HEIGHT=0></IMG>
  307. <DIV>
  308. </BODY>
  309. </HTML>