ASP + WMI

  目次





  指定日のイベントログ



  
<%
Call Response.AddHeader( "Content-Type", "text/html; Charset=shift_jis" )
Response.ExpiresAbsolute=#May 31,2000 23:59:59#

Dim strList,strMessage,strDate
Dim Buff()	' 書込バッファ

' **********************************************************
' MODEL
' **********************************************************
Sub Bset( strValue )

	if IsEmpty( Buff(0) ) then
		Buff(0) = strValue
	else
		ReDim Preserve Buff(Ubound(Buff)+1)
		Buff(Ubound(Buff)) = strValue
	end if

End Sub

function EnumEventLog()

	Redim Buff(0)

	Target = Cdate(strDate)
	if Len( Date ) = 8 then
		Target = "20" & Target
	end if
	TargetStart = Replace( Target, "/", "" ) & "000000.000000+540"
	TargetEnd = Replace( Target, "/", "" ) & "235959.000000+540"

	Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") 
	Set colEvents = objWMIService.ExecQuery _ 
		("Select * from Win32_NTLogEvent Where TimeWritten >= '" _ 
		& TargetStart & "' and TimeWritten <= '" & TargetEnd & "'") 

	Bset "<TABLE cellspacing=1 cellpadding=5 bgcolor=black>"
	strTH = "<TH bgcolor=silver>"
	Bset strTH & "Category</TH>"
	Bset strTH & "ComputerName</TH>"
	Bset strTH & "EventCode</TH>"
	Bset strTH & "Message</TH>"
	Bset strTH & "RecordNumber</TH>"
	Bset strTH & "SourceName</TH>"
	Bset strTH & "TimeWritten</TH>"
	Bset strTH & "Type</TH>"
	Bset strTH & "User</TH>"
	strTD = "<TD bgcolor=white nowrap>"
	For each objEvent in colEvents
		Bset "<TR>"
		Bset strTD & objEvent.Category & "</TD>"
		Bset strTD & objEvent.ComputerName & "</TD>"
		Bset strTD & objEvent.EventCode & "</TD>"
		Bset "<TD bgcolor=white>" & objEvent.Message & "</TD>"
		Bset strTD & objEvent.RecordNumber & "</TD>"
		Bset strTD & objEvent.SourceName & "</TD>"
		Bset strTD & objEvent.TimeWritten & "</TD>"
		Bset strTD & objEvent.Type & "</TD>"
		Bset strTD & objEvent.User & "</TD>"
		Bset "</TR>"
	Next 
	Bset "</TABLE>"

end function

' **********************************************************
' CONTROL
' **********************************************************
	if Request.Form("Date") = "" then
		strDate = Date()
	else
		strDate = Request.Form("Date")
	end if

	if Request.Form( "send" ) = "表示" then
		Call EnumEventLog()
	end if

%>

<!-- **********************************************************
  VIEW
*********************************************************** -->
<FORM method=POST>

<OBJECT
	classid=clsid:20DD1B9E-87C4-11D1-8BE3-0000F8754DA1
	name=Date
	height=25
	width=120
>
	<PARAM NAME="CurrentDate" VALUE="<%= Clng(Cdate( strDate )) %>">
</OBJECT>
<INPUT type=submit name=send value="表示">
<HR>
<%= strMessage %>

<PRE>
<%= Join( Buff, "" ) %>
</PRE>

</FORM>
  



  スリープ関数

  
<%
Call Response.AddHeader( "Content-Type", "text/html; Charset=shift_jis" )
Response.ExpiresAbsolute=#May 31,2000 23:59:59#

Dim strMessage

' **********************************************************
' MODEL
' **********************************************************
function Sleep( nSecond )

	Dim objWMIService,colOSes,objOS,Target
	Dim obj,objEvents,objLatestEvent

	Set objWMIService = GetObject("winmgmts:" _
	 & "{impersonationLevel=impersonate}!\\.\root\cimv2")

	Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
	For Each objOS in colOSes
		Target = objOS.LocalDateTime
	Next

	Set obj = GetObject("winmgmts:\\.\root\cimv2")
	Set objEvents = obj.ExecNotificationQuery( _
		"select * from __InstanceModificationEvent " & _
		"within " & nSecond & " " & _
		"where TargetInstance isa 'Win32_OperatingSystem' " & _
		"and TargetInstance.LocalDateTime > '" & Target & "'" _
	)

	Set objLatestEvent = objEvents.NextEvent 

end function

' **********************************************************
' CONTROL
' **********************************************************
	if Request.Form( "send" ) = "実行" then
		strMessage = Time()
		Call Sleep( Request.Form( "Second" ) )
		strMessage = strMessage & " --> " & Time()
	end if

%>

<!-- **********************************************************
  VIEW
*********************************************************** -->
<FORM method=POST>
秒数 
<SELECT name=Second>
<OPTION value=5>5
<OPTION value=10>10
<OPTION value=15>15
<OPTION value=20>20
</SELECT>
<INPUT type=submit name=send value="実行">
<HR>
<%= strMessage %>
</FORM>
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加




SQLの窓  天気  IT用語辞典
Yahoo!ニュース  マルチ辞書
PHP マニュアル  Google URL短縮 


フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ