Solved

Run Program using VBScript

Posted on 2014-03-28
3
101 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
Pasha Kravtsov earned 500 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

630 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