博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Disk Space Checking
阅读量:5964 次
发布时间:2019-06-19

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

On Error Resume Next

Dim fso, DiskDriver,DD,Showfreespace,Totalsizespace,SizePercent

Dim SendmailPermission

SendmailPermission = 0

Set fso = wscript.createobject("scripting.filesystemobject")

If (fso.folderexists("C:\Disk2")) = False then 

Set foldr=fso.createfolder("C:\Disk2") 

End if 

Set tf = fso.CreateTextFile("c:\Disk2\DiskSpacelog.txt", True)

Set Drivers = fso.Drives

For Each DiskDriver in Drivers

'list all drives in the computer    

DD = DiskDriver.DriveLetter 

Set drv = fso.GetDrive( DD & ":") 

s=drv.DriveType

  If s = 2 And DD <> "Q" Then 

      Showfreespace = DD & " Local Disk Free Space is " & FormatNumber (drv.FreeSpace/1024/1024/1024,1) & "GB"

      'WScript.Echo Showfreespace

      tf.WriteLine Showfreespace

      

      

      Totalsizespace = DD & " Local Disk Total Size is " & FormatNumber (drv.TotalSize/1024/1024/1024,1) & "GB"

      

      'WScript.Echo Totalsizespace

      'tf.WriteLine Totalsizespace

      

      SizePercentNumber= drv.FreeSpace / drv.TotalSize * 100

      

      SizePercent = "Free Space Size Percent is " & FormatNumber (drv.FreeSpace / drv.TotalSize * 100,2) & "%"

      

      'WScript.Echo SizePercent

      

      tf.WriteLine SizePercent

      tf.WriteLine "=================================="

      

      Showfreespace = Null

      

      Totalsizespace = Null

      

      SizePercent = Null

      

      If SizePercentNumber < 11 Then 

      

      SendmailPermission = 1

      

      End If 

      

  End If

 

Next 

MyDate = "Checking Date is " & Date

tf.WriteLine MyDate

tf.Close()

If SendmailPermission = 1 Then 

sendmailresult=SendMail("srv10101@hm.com","Welcome1","DLLOCALIT-CNSH@hm.com","Warning:Low Free Disk Space On Srv10101", "Warning:free disk space is less than 11% on Srv10101 !!!","C:\disk2\DiskSpacelog.txt")

'sendmailresult=SendMail("srv10101@hm.com","Welcome1","eric.fu@hm.com","Srv10101 Disk Space Checking", "Warning:Srv10101 have low free disk space !!!","C:\disk2\DiskSpacelog.txt")

End If 

Function SendMail(SendFrom,Password,SendTo,MailTopic,MailBody,MailAttachment)

    On error resume next

    MS_Space = "http://schemas.microsoft.com/cdo/configuration/"

    Set Email = CreateObject("CDO.Message")

    Email.BodyPart.Charset = "GBK"

    Email.From = SendFrom

    Email.To = SendTo

    Email.Subject = MailTopic

    Email.Htmlbody = MailBody

    If MailAttachment <> "" Then

        For i=0 to Ubound(Split(MailAttachment,";"))

            Email.AddAttachment Split(MailAttachment,";")(i)

        Next

    End If

    With Email.Configuration.Fields

        .Item(MS_Space&"sendusing") = 2

        .Item(MS_Space&"smtpserver") = "smtp."&Split(SendFrom,"@",-1, vbTextCompare)(1)

        .Item(MS_Space&"smtpserverport") = 25

        .Item(MS_Space&"smtpauthenticate") = 1

        .Item(MS_Space&"sendusername") =Split(SendFrom,"@",-1,vbTextCompare)(0)

        .Item(MS_Space&"sendpassword") = Password

        .Update

    End With

    Err.clear

    Email.Send

    If Err.number<>0 Then

        SendMail=False

    Else

        SendMail=True

    End If

    Set Email=Nothing

End Function

本文转自 bilinyee博客,原文链接:     http://blog.51cto.com/ericfu/1668943   如需转载请自行联系原作者

你可能感兴趣的文章
Ackermann Steering System
查看>>
MS CRM 2011的自定义和开发(11)——插件(plugin)开发(一)
查看>>
C#中静态和非静态的区别
查看>>
SQL SERVER 修改数据库名称(包括 db.mdf 名称的修改)
查看>>
详解定位与定位应用
查看>>
fiddler(二)、配置抓取https协议
查看>>
在Vue中Router详细引用
查看>>
cocos2dx 实现文字的一键复制功能(IOS、Android)
查看>>
sqlserver 2012中实现字符串连接的新方法
查看>>
【419】C语言语句
查看>>
python 网络编程第一版
查看>>
PHP 简单调用rest WebServices
查看>>
php环境配置
查看>>
[转载]在Windows Azure Store上购买第三方服务
查看>>
转 Jona Dany 一个20年架构师程序员的经验总结
查看>>
this关键字
查看>>
java异常处理
查看>>
利用反射api查找一个类的具体信息
查看>>
Python 头部 #!/usr/bin/python 和 #!/usr/bin/env python的区别
查看>>
windows mysql 自动备份的几种方法
查看>>