VB Script determines the number of files in the folder and sends a mail warning.

Source: Internet
Author: User

 

Recently, users have a need to monitor the number of files in the folder. If the threshold is exceeded, send a mail warning. I found some VB script code on the Internet and modified it myself.

 

The source code is as follows:

 

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 address

 

Strcomputer = "."

 

Set ob1_miservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")

 

Do While true

Set colfilelist = obw.miservice. 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 '-- one hour

Loop

 

'Use the SMTP server to send emails

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' do not perform verification

. 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

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.