Solved

Run Program using VBScript

Posted on 2014-03-28
3
50 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
3 Comments
 
LVL 5

Accepted Solution

by:
Pasha Kravtsov earned 500 total points
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now