Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Run Program using VBScript

Posted on 2014-03-28
3
Medium Priority
?
128 Views
Last Modified: 2016-06-17
Hi!

I am looking for guidance on creating a script that will run a program and send an email when the task has finished executed.

It would be good to have the script start from a batch file.
0
Comment
Question by:Annette Wilson, MSIS
2 Comments
 
LVL 5

Accepted Solution

by:
Pasha Kravtsov earned 2000 total points
ID: 39961915
I know this isn't VBScript but Python is wayyyy better.
#!/usr/bin/python2
import subprocess
import smtplib

from email.mime.text import MIMEText

#or if you're using linux /link/to/bin/exec
subprocess.call(['C:\\path\\to\\executable.exe'])

#textfile.txt should be in the same directory with your email message containing only ASCII characters
fp = open(textfile.txt, 'rb')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of %s' % textfile
msg['From'] = me
msg['To'] = you

# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()

Open in new window

0
 

Author Comment

by:Annette Wilson, MSIS
ID: 39962067
That's Kool!  I'm learning a new language.

I'm doing the following in AutoIT.  Can I do this in Python?


Dim $Database

 

$oShell = ObjCreate("shell.application")

$oShell.MinimizeAll

 

$Database = "DatabaseName"

$Run = "C:\Program Files\Visual\vmfg\VMPLNWIN.exe -d " & $Database & " -u UserName -p Password"

Run($Run)

Sleep(5000)

WinWaitActive("Material Planning Window")

Sleep(5000)

WinWaitActive("Material Planning Window - Infor ERP VE - [Material Planning Window]")

Send("{ALT}")

Send("{F}")

Send("{DOWN 8}")

Send("{ENTER}")

Send("{UP}")

Sleep(6000)

Send("{ENTER}")


WinWaitClose("VISUAL MRP(tm)-Material Requirements Planning")

Sleep(3000)

Send("{ALT}")

Send("{F}")

Send("{X}")

Sleep (3000)

WinClose("Material Planning Window - Infor ERP VE - [Material Planning Window]")



$SmtpServer = "IPToServer"              ; address for the smtp-server to use - REQUIRED
 $FromName = "MRP_Utility"        ; name from who the email was sent
 $FromAddress = "AutoIT_MRP@ontic.com" ; address from where the mail should come
 $ToAddress = "GroupEmail"   ; destination address of the email - REQUIRED
 $Subject = "MRP Has Successfully Completed"                   ; subject from the email - can be anything you want it to be
 $Body = "This is notification that MRP has successfully completed."      ; the messagebody from the mail - can be left blank but then you get a blank mail
 $AttachFiles = ""                       ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
 $CcAddress = "CopyUsers"    	; address for cc - leave blank if not needed
 $BccAddress = ""     					; address for bcc - leave blank if not needed
 $Importance = "High"                  ; Send message priority: "High", "Normal", "Low"
 $Username =""                    ; username for the account used from where the mail gets sent - REQUIRED
 $Password = 	""                  ; password for the account used from where the mail gets sent - REQUIRED
 $IPPort = 25                            ; port used for sending the mail
 $ssl = 0       


 $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
 		;==>_SendMail
 ; The UDF
 Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)

    Local $objEmail = ObjCreate("CDO.Message")
     $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
     $objEmail.To = $s_ToAddress

     If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
     If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
     $objEmail.Subject = $s_Subject
     If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
         $objEmail.HTMLBody = $as_Body
     Else
         $objEmail.Textbody = $as_Body & @CRLF
     EndIf
     If $s_AttachFiles <> "" Then
         Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
         For $x = 1 To $S_Files2Attach[0]
            ; $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
        ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
             If FileExists($S_Files2Attach[$x]) Then
                ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
                 $objEmail.AddAttachment($S_Files2Attach[$x])
 					Sleep(200)
             Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)

                 Return 0
             EndIf
         Next
     EndIf
     $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
     If Number($IPPort) = 0 then $IPPort = 25
     $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
     ;Authenticated SMTP
     If $s_Username <> "" Then
         $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
         $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
         $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
     EndIf
     If $ssl Then
         $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
     EndIf
     ;Update settings
     $objEmail.Configuration.Fields.Update
     ; Set Email Importance
     Switch $s_Importance
         Case "High"
             $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
         Case "Normal"
             $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
         Case "Low"
             $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
     EndSwitch
     $objEmail.Fields.Update
     ; Sent the Message
     $objEmail.Send
     If @error Then

 	Else

     EndIf
     $objEmail=""
  EndFunc 	;==>_INetSmtpMailCom



Exit

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question