Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:31:19+00:00 2026-06-07T00:31:19+00:00

How can I pass a parameter from batch to vbscript? My batch script sends

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:31:22+00:00Added an answer on June 7, 2026 at 12:31 am

    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:

    cscript //nologo fail_mail.vbs something.sql 'something.sql is the param. that i'm passing.
    

    Here is what my vbscript for mail looks like:

    Const ForReading = 1
    
    Set args = WScript.Arguments
    arg1 = args.Item(0)  'the parameter from batch comes in here to arg1
    ...
    ...
    ToAddress = "my@address.com"
    MessageSubject = "WORKED"
    MessageBody = "Success" 
    MessageAttachment = ""&arg1&""  'here those quotes are important. dk why.
    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
    

    And it is working.
    *One can pass more than one parameters using the same technique.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see that with SQL Server 2005 you can pass a parameter as numeric
I know that I can pass a string as the second parameter to the
can anyone give me an idea about how to pass parameter from objective c
How can I pass a parameter to a fabric task when calling fab from
Can any body help me in knowing how to pass a parameter from a
How can I pass more than one parameter from jQuery to an ASHX file.
How can I Pass parameter from FormPanel of GWT to Servlet? FormPanel formPanel =
How can I pass the Parameter to a function. for example public void GridViewColumns(params
I am trying to pass the parameter, which is 'priceValue'. How can I pass
How can I pass an optional parameter to the flash message? I'm using Twitter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.