代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
VBS
】
自动 服务器检查 的vbs脚本
作者:
/ 发布于
2016/1/25
/
1222
strDebug = "0" If strDebug = "0" Then SearchServer "ServerName1","X.X@corp.com","X.X@corp.com" SearchServer "ServerName2","X.X@corp.com","X.X@corp.com" End If 'Main Function Function SearchServer(strServer, strRecipient, strCC) strBody="<hr><b style=""color:red;font-size:16px"">[ " & ucase(strServer) & " ]</b>" 'Get Disk Information strBody = strBody & GetDiskInfo(strServer) 'Get Service Status strBody = strBody & GetServiceStatus(strServer) 'Get Event Log strBody = strBody & "<BR><b style=""color:blue;font-size:14px"">Event Log</b><BR><Table border=1><TR bgcolor=""plum""><TD>Type</TD><TD>Event Type</TD>" & _ "<TD>Source Name</TD><TD>Event Code</TD><TD>Record Number</TD>" & _ "<TD>Time Written</TD><TD>Message</TD><TD>User</TD></TR>" & VBCRLF strComputer = strServer strType = "Application" strLog = GetLog (strComputer,strType) strBody = strBody & strLog strType = "System" strLog = GetLog (strComputer,strType) strBody = strBody & strLog & "</Table>" 'WScript.Echo strBody 'exit function 'Notify the administrator of this server. SendMail replace(strBody,"'",""""),"Server Daily Information - " & replace(strRecipient,"@Qisda.com",""), strRecipient, strCC End Function Function SendMail(strBody, strSubject, strRecipient, strCC) Set conMail=CreateObject("ADODB.Connection") conMail.open "Provider=SQLOLEDB.1;Data Source=*****;Initial Catalog=MailService;User ID=*****;Password=*****" sendTime=cstr(year(now)) & "-" & cstr(month(now)) & "-" & cstr(day(now)) & " 8:00:00" conMail.execute "exec SP_MS_MAIL_ADD 'ServerInfo','Mail','','"+strRecipient+"','"+strCC+"','','"+strSubject+"','"+strBody+"','','M','"+sendTime+"','ServerInfo','<head><meta http-equiv=Content-Type content=""text/html; charset=gb2312""><style>html,body,td,b,p { font-family:Verdana; font-size:11px; }</style></head>'" conMail.close End Function Function GetDiskInfo(strServer) Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strServer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk Where DriveType = 3") strTemp = "<BR><b style=""color:blue;font-size:14px"">Disk Info</b><BR><Table border=1><TR bgcolor=""plum""><TD>Disk ID</TD><TD align=right>Total Size</TD><TD align=right>Free Size</TD><TD align=right>Percent of Free Space</TD></TR>" & VBCRLF For Each objDisk in colDisks intFreeSpace = round(objDisk.FreeSpace / 1024 / 1024 / 1024, 1) intTotalSpace = round(objDisk.Size / 1024 / 1024 / 1024, 1) pctFreeSpace = intFreeSpace / intTotalSpace strBackgrand = "" If pctFreeSpace < 0.3 Then strBackgrand = "bgcolor=""#99cc66""" If pctFreeSpace < 0.2 Then strBackgrand = "bgcolor=""#ff9999""" strTemp = strTemp & "<TR " & strBackgrand & "><TD>" & objDisk.DeviceID & "</TD><TD>" & intTotalSpace & "G</TD><TD>" & _ intFreeSpace & "G</TD><TD>" & FormatPercent(pctFreeSpace) & "</TD></TR>" & VBCRLF Next strTemp = strTemp & "</Table>" GetDiskInfo = strTemp End Function Function GetLog(strComputer,strType) Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate,(Security)}!\\" & _ strComputer & "\root\cimv2") 'EventType = 1 Error EventType = 2 Warning Set colLoggedEvents = objWMIService.ExecQuery _ ("Select * FROM Win32_NTLogEvent WHERE Logfile = '" & strType & "' " & _ "AND (EventType =1 or EventType = 2) AND TimeGenerated > '" & GetYestoday & "' ") max=1 For Each objEvent in colLoggedEvents dtmEventDate = objEvent.TimeWritten strTimeWritten = WMIDateStringToDate(dtmEventDate) strBackgrand = "" If (LCase(objEvent.Type) = "error" or objEvent.Type="错误") Then strBackgrand = "bgcolor=""ff9999""" strTemp = strTemp & "<TR " & strBackgrand & ">" & _ "<TD>" & strType & "</TD>" & "<TD>" & objEvent.Type & "</TD>" & _ "<TD>" & objEvent.SourceName & "</TD>" & _ "<TD>" & objEvent.EventCode & "</TD>" & "<TD>" & objEvent.RecordNumber & "</TD>" & _ "<TD>" & strTimeWritten & "</TD>" & "<TD>" & left(objEvent.Message,200) & " ...</TD>" & _ "<TD>" & objEvent.User & "</TD></TR>" & VBCRLF max=max+1 if (max>20) then exit for end if Next GetLog = strTemp End Function Function GetYestoday strYear=cstr(year(now()-1)) strMonth=cstr(month(now()-1)) if len(strMonth)=1 then strMonth="0" & strMonth strDay=cstr(day(now()-1)) if len(strDay)=1 then strDay="0" & strDay GetYestoday=strYear & strMonth & strDay End Function Function WMIDateStringToDate(dtmEventDate) WMIDateStringToDate = CDate(Mid(dtmEventDate, 5, 2) & "/" & _ Mid(dtmEventDate, 7, 2) & "/" & Left(dtmEventDate, 4) _ & " " & Mid (dtmEventDate, 9, 2) & ":" & _ Mid(dtmEventDate, 11, 2) & ":" & Mid(dtmEventDate, _ 13, 2)) End Function Function GetServiceStatus(strServer) Set objWMIService = GetObject("winmgmts:\\" & strServer & "\root\cimv2") strTemp = "<BR><b style=""color:blue;font-size:14px"">Service Status</b><BR><Table border=1><TR bgcolor=""plum""><TD>Service Name</TD><TD> Status</TD></TR>" Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name ='MSSQLSERVER'") i=0 For Each objService in colServiceList strBackcolor = "" If LCase(objService.State) = "stopped" Then strBackcolor = " bgcolor = ""#ff9999""" strTemp = strTemp + "<TR" & strBackcolor & "><TD>MSSQLServer</TD><TD>" & objService.State & "</TD></TR>" i=1 Next if i=0 then strTemp = strTemp + "<TR><TD>MSSQLSERVER</TD><TD>No Service</TD></TR>" Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name ='SQLSERVERAGENT'") i=0 For Each objService in colServiceList strBackcolor = "" If LCase(objService.State) = "stopped" Then strBackcolor = " bgcolor = ""#ff9999""" strTemp = strTemp + "<TR" & strBackcolor & "><TD>" & objService.Name & "</TD><TD>" & objService.State & "</TD></TR>" i=1 Next if i=0 then strTemp = strTemp + "<TR><TD>SQLSERVERAGENT</TD><TD>No Service</TD></TR>" Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name ='W3SVC'") i=0 For Each objService in colServiceList strBackcolor = "" If LCase(objService.State) = "stopped" Then strBackcolor = " bgcolor = ""#ff9999""" strTemp = strTemp + "<TR" & strBackcolor & "><TD>World Wide Web Publishing Service</TD><TD>" & objService.State & "</TD></TR>" i=1 Next if i=0 then strTemp = strTemp + "<TR><TD>World Wide Web Publishing Service</TD><TD>No Service</TD></TR>" Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name ='ntrtscan'") i=0 For Each objService in colServiceList strBackcolor = "" If LCase(objService.State) = "stopped" Then strBackcolor = " bgcolor = ""#ff9999""" strTemp = strTemp + "<TR" & strBackcolor & "><TD>OfficeScanNT RealTime Scan</TD><TD>" & objService.State & "</TD></TR>" i=1 Next if i=0 then strTemp = strTemp + "<TR bgcolor = ""#ff9999""><TD>OfficeScanNT RealTime Scan</TD><TD>No Service</TD></TR>" Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name ='OracleOraHome92TNSListener'") i=0 For Each objService in colServiceList strBackcolor = "" If LCase(objService.State) = "stopped" Then strBackcolor = " bgcolor = ""#ff9999""" strTemp = strTemp + "<TR" & strBackcolor & "><TD>OracleOraHome92TNSListener</TD><TD>" & objService.State & "</TD></TR>" i=1 Next if i=0 then strTemp = strTemp + "<TR><TD>OracleOraHome92TNSListener</TD><TD>No Service</TD></TR>" GetServiceStatus = strTemp & "</Table>" End Function
试试其它关键字
同语言下
.
使用脚本将域账号添加到客户机的本地管理员组
.
删除服务器上文件
.
主动ping服务器是否宕机
.
自动 服务器检查 的vbs脚本
.
VBS脚本发送邮件,密送多人,带附件,可更换账号密码
.
根据文件路径复制文件
.
VBA操作数据库
.
双击获取公网IP到剪贴板
.
定时运行ie浏览执行网址不显示浏览器窗口
.
批处理生成日历
可能有用的
.
使用脚本将域账号添加到客户机的本地管理员组
.
删除服务器上文件
.
主动ping服务器是否宕机
.
自动 服务器检查 的vbs脚本
.
VBS脚本发送邮件,密送多人,带附件,可更换账号密码
.
根据文件路径复制文件
.
VBA操作数据库
.
双击获取公网IP到剪贴板
.
定时运行ie浏览执行网址不显示浏览器窗口
.
批处理生成日历
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3