VB Script判断文件夹下文件的数量并发MAIL预警

 

最近用户有个需求,需要监控文件夹下面文件的数量。如果超过一定的阀值需要发MAIL预警。从网上找了些VB Script的代码然后自己修改了一下就可以了。

 

源代码如下:

 

strMessage = "File number more than10, please check"

strTo= "sample@home.cn"

strFrom="sample@home.cn"

strSubject="File number more than 10,please check"

strSMTPServer="smtp.home.cn"'--smtp地址

 

strComputer = "."

 

Set objWMIService =GetObject("winmgmts:\\" & strComputer &"\root\cimv2")

 

Do While True

   Set colFileList = objWMIService.ExecQuery _

       ("ASSOCIATORS OF {Win32_Directory.Name='D:\sample\'} Where " _

           & "ResultClass = CIM_DataFile")

 

    If colFileList.Count >= 10 Then

      SendMail strFrom,strTo,strSubject,strMessage,strSMTPServer

     Exit Do

   End If

 

   Wscript.Sleep 600000'--一小时

Loop

 

' 使用SMTP服务器发送邮件

Function SendMail( strFrom, strSendTo,strSubject, strMessage , strSMTP )

 

         SetoEmail = CreateObject("CDO.Message")

        

         'configuremessage

         WithoEmail.Configuration.Fields

         .Item("http://schemas.microsoft.com/cdo/configuration/sendusing")= 2

         .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")= 25

         .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= strSMTP

         .item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")= 0 '不执行验证

         .Update

         EndWith

        

         'build message

         WithoEmail

              .From = strFrom

              .To = strSendTo

              .Subject = strSubject

              .TextBody = strMessage

         EndWith

        

         'send message

         OnError Resume Next

         oEmail.Send

         IfErr Then

              WScript.Echo "SendMail Failed:"& Err.Description

         EndIf

                  

End Function

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值