我写了一个 .vbs 脚本,用当前的日志文件向管理员发送电子邮件这是我目前所拥有的:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\automatic_deployment\filename.txt", ForReading)
fileName = objTextFile.ReadLine
Wscript.Echo fileName
Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MyTime
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
Dim month
ToAddress = "myaddress@myemail.com"
MessageSubject = "Deployment was successful"
MyTime = Now
MessageBody = "Successful deployment. Log file is attached."
MessageAttachment = "C:\M\XYZ\201206\"&fileName&"_DEV_Log.txt"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf & MyTime
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send
objTextFile.Close
如果您看到,有一个名为“MessageAttachment”的变量,其中附加了日志文件。在日志文件的目标部分,有 201206,代表年和月。该文件夹包含 2012 年 6 月的日志。该月每月递增。如您所见,它是硬编码的。到目前为止它工作正常。但是,我想更进一步,让它更有活力。我想创建一个变量并获取当前月份的当前值,并将其放入源目标的那部分,如下所示:
month = aqDateTime.GetMonth(Date)
MessageAttachment = "C:\M\XYZ\2012"&month&"\"&fileName&"_DEV_Log.txt"
这行得通吗?任何帮助,将不胜感激。提前致谢!