How to pass a parameter from Batch (.bat) to VBScript (.vbs)?

后端 未结 3 1457
难免孤独
难免孤独 2021-01-01 03:13

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) t

3条回答
  •  醉酒成梦
    2021-01-01 03:37

    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.

提交回复
热议问题