How can I pass a parameter from batch to vbscript? My batch script sends out an email at the end of the automated execution. For that it uses/calls my vbscript (email.vbs) that sends out the email with an actual log file (that has the results for that execution) attached.
All those log files are stored in specific folders such as: 201207(July, 2012), 201208(August, 2012) and so on….
I want to pass the folder name or part of (i am thinking about hard coding the 2012 part and get the month number from that parameter through my batch) it as a parameter to my email.vbs so that it can go look for the right folder to grab the right log file. Makes sense?
ECHO Checking the log file for errors...
FINDSTR /C:"RC (return code) = 0" %workDir%\%filenm%_Log.txt && (ECHO Deployment was successful.
ECHO Email is sent out...
cscript //nologo success_mail_DEV.vbs %workDir% 'passing the directory param. here.
ECHO Press ENTER to exit...
GOTO offshore) || (ECHO Deployment was not successful. Errors were found!
ECHO Email is sent out...
ECHO Press ENTER to exit...
cscript //nologo fail_mail_DEV.vbs %workDir% 'and here
GOTO offshore)
This is part of what I have right now. It is checking for errors in the log file and calling that success/failed mail accordingly. Right now the location name/number is hardcoded in those 2 vbs mailing scripts that you see up there. I am sure there is a way to pass a parameter somewhere up there to the emailing vbscript. But, i don’t know how to.
This is my mailing vbscript:
Const ForReading = 1
Set args = WScript.Arguments
directory = args.Item(0) 'thought that workDir would come in here
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(&directory&"\filename.txt", ForReading)
fileName = objTextFile.ReadLine
Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MyTime
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
MyTime = Now
ToAddress = "destination@email.com"
MessageSubject = "SUCCESS"
MessageBody = "It was successful"
MessageAttachment = &directory&"\"&fileName&"_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
But not working…
Thanks in advance!
Alright, I am updating that question I had. It’s finally working, with all of your help, guys.
Thanks.
Here is how I called the vbscript and passed a parameter to it:
Here is what my vbscript for mail looks like:
And it is working.
*One can pass more than one parameters using the same technique.