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.
 
 
 
 
 
 

389 lines
12 KiB

<HTML>
<HEAD>
<TITLE> WMI DEMO
</TITLE>
<SCRIPT LANGUAGE="VBSCRIPT">
CONST CONST_REBOOT_FORCE = 6
CONST CONST_REBOOT_NOFORCE = 2
Dim theService
Dim theEventsService
Dim theLocator
Dim theEventsWindow
Dim memoryInfo
Dim cpuInfo
Dim cdromInfo
Dim diskInfo
Dim MyMapiSession
Dim currentTemp
' Initialize Globals
Sub window_onLoad()
memoryInfo = ""
cpuInfo = ""
cdromInfo = ""
diskInfo = ""
currentTemp = "cold"
Set MyMapiSession = CreateObject("MSMAPI.MAPISession")
MyMapiSession.SignOn
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:\winnt00\system32\wbem\sound.exe", null, null, intProcessId)
intStatus = classObject.Create("c:\winnt00\system32\Dllcache\mplayer2.exe c:\winnt\media\alarm.wav", null, null, intProcessId)
End Sub
Sub RebootMachine
On Error Resume Next
theEventsWindow.value = "Trying Reboot ..." & theEventsWindow.value
for each theOS in theService.InstancesOf ("Win32_OperatingSystem")
theOS.Win32ShutDown(6)
If Err <> 0 Then
theEventsWindow.value = "ExecMethod Error : " & Err.Description & " on " & theOS.Path_.path
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 = "demoacc"
mapiMessages.RecipAddress = "[email protected]"
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", "Administrator", " ")
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", "Administrator", " ")
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 wmiclient.wmidemodomain 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 wmiclient.wmidemodomain 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 wmiclient.wmidemodomain 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 wmiclient.wmidemodomain 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
' Start the temperature monitor
theEventsService.ExecNotificationQueryAsync theCPUSink, _
"select * from iia_temperatureEvent"
If Err <> 0 Then
theEventsWindow.Value = theEventsWindow.Value & "ExecQuery iia_temperature Error : " & Err.Description
End if
' Start the Box monitor
theEventsService.ExecNotificationQueryAsync theBoxSink, _
"select * from iia_intrusionDetectionEvent"
If Err <> 0 Then
theEventsWindow.Value = theEventsWindow.Value & "ExecQuery iia_intrusion 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
ShowCD
Else
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
MakeHottest
Else
MakeCold
End If
</SCRIPT>
</HEAD>
<BODY>
<OBJECT ID="theCDSink" CLASSID="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></OBJECT>
<OBJECT ID="theCPUSink" CLASSID="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></OBJECT>
<OBJECT ID="theBoxSink" CLASSID="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></OBJECT>
<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"
VALUE="w7-blue-2-nt4">
</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 STYLE="VISIBLE;HIDDEN">
</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>