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.

388 lines
12 KiB

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