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.
 
 
 
 
 
 

378 lines
12 KiB

<HTML>
<HEAD>
<TITLE> Monitor
</TITLE>
<SCRIPT LANGUAGE="VBSCRIPT">
CONST CONST_REBOOT_FORCE = 6
CONST CONST_REBOOT_NOFORCE = 2
Dim theService
Dim theEventsService
Dim theLocator
Dim theEventsWindow
Dim theCDSink
Dim theCPUSink
Dim theBoxSink
Dim memoryInfo
Dim cpuInfo
Dim cdromInfo
Dim diskInfo
Dim MyMapiSession
' Initialize Globals
Sub window_onLoad()
memoryInfo = ""
cpuInfo = ""
cdromInfo = ""
diskInfo = ""
'Set MyMapiSession = CreateObject("MSMAPI.MAPISession")
'MyMapiSession.SignOn
set theCDSink = CreateObject("WbemScripting.SWbemSink")
set theCPUSink = CreateObject("WbemScripting.SWbemSink")
set theBoxSink = CreateObject("WbemScripting.SWbemSink")
alert("Done init")
End Sub
Sub SoundAlarm
' Start a couple of services
Set theLocalService = theLocator.ConnectServer
theLocalService.Security_.impersonationLevel = 3
Dim classObject
Set classObject = theLocalService.Get ( "Win32_Process" )
Dim intProcessId
Dim intStatus
intStatus = classObject.Create("c:\winnt\system32\wbem\sound.exe", null, null, intProcessId)
End Sub
Sub RebootMachine
theEventsWindow.value = theEventsWindow.value & "Reboot Machine Called"
On Error Resume Next
for each machine in theService.InstancesOf ("Win32_OperatingSystem")
theEventsWindow.value = theEventsWindow.value & "Trying reboot on " & machine.Path_path
machine.Win32ShutDown 6
If Err <> 0 Then
theEventsWindow.value = "CreateObject Error : " & Err.Description
End if
next
End Sub
Sub Sendmail ( Subject , Message )
'
' Send a mail message using mapi
'
Dim mapiMessages
Set mapiMessages = CreateObject("MSMAPI.MAPIMessages")
mapiMessages.SessionID = MyMapiSession.SessionID
mapiMessages.Compose
mapiMessages.RecipDisplayName = "Steve Menzies"
mapiMessages.RecipAddress = "stevm"
mapiMessages.AddressResolveUI = True
mapiMessages.ResolveName
mapiMessages.MsgSubject = Subject
mapiMessages.MsgNoteText = Message
mapiMessages.Send False
' MyMapiSession.SignOff
End Sub
'
' Gets machine info and starts monitoring
'
Sub GetMachineInfo()
On Error Resume Next
' Set globals
Set theEventsWindow = Document.all("EventsWindow")
theEventsWindow.value = "EventsWindow"
' Create the Locator
Set theLocator = CreateObject("WbemScripting.SWbemLocator")
If Err <> 0 Then
theEventsWindow.value = "CreateObject Error : " & Err.Description
End if
' Start a couple of services
Set theService = theLocator.ConnectServer( Machine.Value, "root\cimv2", "redmond\stevm", "wmidemo_2000")
If Err <> 0 Then
theEventsWindow.value = theEventsWindow.value & "ConnectServer Error : " & Err.Description
End if
theService.Security_.impersonationLevel = 3
Set theEventsService = theLocator.ConnectServer( Machine.value, "root\cimv2", "redmond\stevm", "wmidemo_2000")
If Err <> 0 Then
theEventsWindow.value = theEventsWindow.value & "ConnectServer for events service Error : " & Err.Description
End if
theEventsService.Security_.impersonationLevel = 3
' Get the information
'GetCPUInfo
'GetMemoryInfo
'GetDiskInfo
'GetCDROMInfo
StartMonitoring
End Sub
Sub ShowCD
On Error Resume Next
Dim theImage
Set theImage = document.all("theCDROM")
theImage.height = 200
theImage.width = 200
End Sub
Sub HideCD
On Error Resume Next
Dim theImage
Set theImage = document.all("theCDROM")
theImage.height = 0
theImage.width = 0
End Sub
Sub OpenBox
On Error Resume Next
Dim theImage
Set theImage = document.all("theBoard")
theImage.src = "mboardCool.jpg"
Sendmail "Machine Opened!", "The box of the machine outsoft9.dns.microsoft.com has been opened!"
SoundAlarm
End Sub
Sub CloseBox
On Error Resume Next
Dim theImage
Set theImage = document.all("theBoard")
theImage.src = "computer.jpg"
Sendmail "Machine Closed!" , "The box of the machine outsoft9.dns.microsoft.com has been closed!"
End Sub
Sub MakeCold
On Error Resume Next
Dim theImage
Set theImage = document.all("theBoard")
theImage.src = "mboardCool.jpg"
Sendmail "Machine temperature back to normal!", "The motherboard of the machine outsoft9.dns.microsoft.com has returned to normal temperature!"
End Sub
Sub MakeHotter
On Error Resume Next
Dim theImage
Set theImage = document.all("theBoard")
theImage.src = "mboardHot.jpg"
End Sub
Sub MakeHottest
On Error Resume Next
Dim theImage
Set theImage = document.all("theBoard")
theImage.src = "mboardHottest.jpg"
Sendmail "Machine temperature at ABNORMAL level!", "The motherboard of the machine outsoft9.dns.microsoft.com has gone beyond the threshold of 35 Degrees Centigrade!"
SoundAlarm
End Sub
'
' Gets information about the processors
'
Sub GetCPUInfo()
On Error Resume Next
cpuInfo = ""
i = 0
for each Processor in theService.InstancesOf ("Win32_Processor")
cpuInfo = cpuInfo & Chr(13) & Processor.Name & " Revision: " & Processor.Revision
cpuInfo = cpuInfo & Chr(13) & "DeviceID: " & Processor.DeviceID
cpuInfo = cpuInfo & Chr(13) & "Description: " & Processor.Description
cpuInfo = cpuInfo & Chr(13) & "AddressWidth: " & Processor.AddressWidth
cpuInfo = cpuInfo & Chr(13) & "DataWidth: " & Processor.DataWidth
cpuInfo = cpuInfo & Chr(13) & "CurrentClockSpeed: " & Processor.CurrentClockSpeed
i = i+1
next
cpuInfo = "Number of Processors = " & i & cpuInfo
End Sub
'
' Gets information about the memory
'
Sub GetMemoryInfo()
memoryInfo = ""
On Error Resume Next
i = 0
for each Mem in theService.InstancesOf ("win32_logicalMemoryConfiguration")
memoryInfo = memoryInfo & "Total Physical Memory: " & Mem.TotalPhysicalMemory & " Kilo Bytes"
i = i+1
next
End Sub
'
' Gets information about the cdrom drive
'
Sub GetCDROMInfo()
On Error Resume Next
cdromInfo = ""
i = 0
for each Drive in theService.InstancesOf ("Win32_CDRomDrive")
cdromInfo = cdromInfo & Chr(13) & "DeviceID: " & Drive.DeviceID
cdromInfo = cdromInfo & Chr(13) & "Description: " & Drive.Description
cdromInfo = cdromInfo & Chr(13) & "Caption: " & Drive.Caption
cdromInfo = cdromInfo & Chr(13) & "MediaType: " & Drive.MediaType
cdromInfo = cdromInfo & Chr(13) & "Manufacturer: " & Drive.Manufacturer
cdromInfo = cdromInfo & Chr(13) & "MediaLoaded: " & Drive.MediaLoaded
if Drive.MediaLoaded then
ShowCD
cdromInfo = cdromInfo & Chr(13) & "VolumeName: " & Drive.VolumeName
end if
i = i + 1
next
cdromInfo = "Number of CDROM drives = " & i & cdromInfo
End Sub
'
' Gets information about the disks
'
Sub GetDiskInfo()
On Error Resume Next
diskInfo = ""
i = 0
for each Drive in theService.InstancesOf ("Win32_DiskDrive")
diskInfo = diskInfo & Chr(13) & "DeviceID: " & Drive.DeviceID
diskInfo = diskInfo & Chr(13) & "Description: " & Drive.Description
diskInfo = diskInfo & Chr(13) & "Caption: " & Drive.Caption
diskInfo = diskInfo & Chr(13) & "Size: " & Drive.Size
diskInfo = diskInfo & Chr(13) & "BytesPerSector: " & Drive.BytesPerSector
diskInfo = diskInfo & Chr(13) & "SectorsPerTrack: " & Drive.SectorsPerTrack
diskInfo = diskInfo & Chr(13) & "InterfaceType: " & Drive.InterfaceType
diskInfo = diskInfo & Chr(13) & "MediaType: " & Drive.MediaType
diskInfo = diskInfo & Chr(13) & "Manufacturer: " & Drive.Manufacturer
diskInfo = diskInfo & Chr(13) & "Number of partitions: " & Drive.Partitions
diskInfo = diskInfo & Chr(13) & "TotalCylinders: " & Drive.TotalCylinders
diskInfo = diskInfo & Chr(13) & "TotalHeads: " & Drive.TotalHeads
diskInfo = diskInfo & Chr(13) & "TotalHeads: " & Drive.TotalHeads
diskInfo = diskInfo & Chr(13) & "TracksPerCylinder: " & Drive.TracksPerCylinder
i = i+1
next
diskInfo = "Number of Disks = " & i & diskInfo
End Sub
Sub StartMonitoring()
On Error Resume Next
If Err <> 0 Then
theEventsWindow.Value = theEventsWindow.Value & "CreateObject WBEMSink Error : " & Err.Description
End if
' Start the CD Monitor
theEventsService.ExecNotificationQueryAsync theCDSink, _
"select * from __instanceModificationEvent within 1 where targetinstance isa 'win32_cdromDrive'"
If Err <> 0 Then
theEventsWindow.Value = theEventsWindow.Value & "ExecQuery CDROM Drive Error : " & Err.Description
End if
End Sub
Sub ShowInfo(theNum)
Select Case theNum
Case 1
MsgBox memoryInfo,,"Physical Memory Details"
Case 2
MsgBox diskInfo,,"Physical Disk Details"
Case 3
MsgBox cpuInfo,,"Processor Details"
Case 4
MsgBox cdromInfo,,"CDROM Drive Details"
End Select
End Sub
</SCRIPT>
<SCRIPT FOR="theCDSink" EVENT="OnObjectReady(objObject, objAsyncContext)" LANGUAGE="VBScript">
' theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: " & objObject.Path_.RelPath
Set theChangedObject = objObject.Properties_("TargetInstance")
If theChangedObject.Value.Properties_("MediaLoaded") = TRUE Then
theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: Showing CD"
ShowCD
Else
theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: Hiding CD"
HideCD
End If
</SCRIPT>
<SCRIPT FOR="theBoxSink" EVENT="OnObjectReady(objObject, objAsyncContext)" LANGUAGE="VBScript">
' theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: " & objObject.Path_.RelPath
If objObject.Properties_("EventDescription") = 2 Then
theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: Opening Box"
OpenBox
Else
theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: ClosingBox"
CloseBox
End If
</SCRIPT>
<SCRIPT FOR="theCPUSink" EVENT="OnObjectReady(objObject, objAsyncContext)" LANGUAGE="VBScript">
'theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: " & objObject.Properties_("EventDescription")
If objObject.Properties_("EventDescription") = 2 Then
theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: Heatin up"
MakeHottest
Else
theEventsWindow.Value = theEventsWindow.Value & "OnObjectReady CallBack Called: Cooling Down"
MakeCold
End If
</SCRIPT>
</HEAD>
<BODY>
<LABEL FOR="Machine" ID="MachineLabel">MACHINE</LABEL>
<INPUT TYPE="text" NAME="Machine" ID="Machine"
SIZE=20
TITLE="The machine from which to get the hardware information">
</INPUT>
<BUTTON NAME="MachineInfo" ID="MachineInfo" onClick=GetMachineInfo>Get Data</BUTTON>
<BUTTON NAME="RebootButton" ID="RebootButton" onClick=RebootMachine>Shutdown Remote Machine</BUTTON>
<TEXTAREA ID="EventsWindow" ROWS=5 COLS=55>
</TEXTAREA>
<DIV>
<IMG ID="theBoard" SRC="computer.jpg" USEMAP="#theMap" BORDER=0 WIDTH=450 HEIGHT=450>
</IMG>
<MAP NAME="theMap" ID="theMap">
<AREA SHAPE=RECT ONCLICK="showInfo(1)" TITLE="Click Here to get Memory Information" COORDS="8,113,100,415">
<AREA SHAPE=RECT ONCLICK="showInfo(2)" TITLE="Click Here to get Disk Drive Information" COORDS="217,8,415,150">
<AREA SHAPE=RECT ONCLICK="showInfo(3)" TITLE="Click Here to get Processor Information" COORDS="100,113,213,415">
<AREA SHAPE=RECT ONCLICK="showInfo(4)" TITLE="Click Here to get CD ROM Information" COORDS="217,155,415,415">
</MAP>
<IMG ID="theCDROM" NAME=theCDROM SRC="cdrom.jpg" BORDER=0 WIDTH=0 HEIGHT=0></IMG>
<DIV>
</BODY>
</HTML>