博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VB Script判断文件夹下文件的数量并发MAIL预警
阅读量:7189 次
发布时间:2019-06-29

本文共 1452 字,大约阅读时间需要 4 分钟。

最近用户有个需求,需要监控文件夹下面文件的数量。如果超过一定的阀值需要发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

 

本文转自 lzf328 51CTO博客,原文链接:

http://blog.51cto.com/lzf328/1252922

转载地址:http://xeykm.baihongyu.com/

你可能感兴趣的文章
Perl语言之统计特定字符串个数
查看>>
Linux用户和组管理
查看>>
Eclipse中从svn上检出项目无法识别jar包
查看>>
shell实现FTP自动批量上传下载文件
查看>>
我的友情链接
查看>>
Mybatis使用存储过程以及原理
查看>>
通讯录二维码使英文变为中文
查看>>
快2012了!
查看>>
【Objective-C】OC中字典基本概念和常用方法(NSDictionary和NSMutableDictionary)
查看>>
maven打包包含配置文件
查看>>
C# readonly与const比较
查看>>
我的友情链接
查看>>
我的大学n糊口
查看>>
设置easyUi弹出窗在弹出框(iframe)中不居中问题
查看>>
&.nbsp;在IE和谷歌浏览器中不兼容的解决办法
查看>>
Servlet容器
查看>>
捷为科技签约镇海石化, 打造石化建安行业生产项目信息化管理系统
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
Java异常
查看>>