Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.NET exe return success or fail to Task or Job

Posted on 2013-01-07
11
Medium Priority
?
638 Views
Last Modified: 2013-01-15
I need to run an VB.NET exe using either Windows Task Scheduler or Sql Server Agent Job.  What do I need to code in the exe so it will report to the task or job if it completed successfully or failed?  

Also, what do I need to add to the task or job so it will wait for the program to complete?


Have never done this before so don't know where to start.  Have been searching the web for 2 days but don't really find what I need.

Thanks for any help in advance.
0
Comment
Question by:McGurk1
[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
  • 5
  • 5
11 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38751333
so you want a win task scheduler to run vb.net exe.
the executable need to report if success or failed.
does the exe need to get parameters?
to whom the exe need to notify if succeed or failed?
do u need to run the task scheduler only one time, in a specific time or every predefined date time?
does the exe write to log file upon success or failure?
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 1000 total points
ID: 38751472
Use the Environment.Exit(ExitCode) to terminate your app and pass your exit code back.


http://msdn.microsoft.com/en-us/library/system.environment.exit.aspx
0
 

Author Comment

by:McGurk1
ID: 38751717
sedgwick,
- no parameters are passed
- need to send email if fails, no need if success
- task scheduler needs to run every night (7/365)
- exe does not write to log file at this time, plan to do that if I can get the response set up from the program
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:McGurk1
ID: 38751734
CodeCruiser,

Will check into Environment.Exit(ExitCode)

Thanks
0
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 1000 total points
ID: 38754437
to run your vb.net exe every night use the following command line (run it once from your command prompt)

schtasks /create /tn "MyTaskName" /tr <exe-full-path> /sc daily /st 22:00

replace MyTaskName with whatever name you wish to give the task scheduler
replace <exe-full-path> with your vb.net exe full path
replace 22:00 to whatever hour you wish to have your exe running
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38754443
if you want to monitor the suceess of your exe outside the application, you can use a script which runs the vb.net exe and send email upon failure or code another small .net application which runs your vb.net exe and send the email upon failure.

i can help you do either one, whatever you feel comfortable with.
0
 

Author Comment

by:McGurk1
ID: 38778971
Am using the following to send an email with the Exit.Code and Exit.Time.  I also store the closing information in the database for future reference.  EmailAlert() is the sub created to send the emails.
 Dim p As New Process
            p.StartInfo.FileName = "path to my exe"
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
            p.StartInfo.CreateNoWindow = True
          Try
                p.Start()
                p.WaitForExit()

           Catch ex As Exception
                PIMessage = ex.Message
                EmailSubject = "Error Running Scheduler"
                EmailMessage = "Error running Scheduler. " & ex.Message
                EmailAlert()
            Finally
                EmailSubject = "MyProgramName"
                EmailMessage = "MyProgramName reports Exit Code = " & p.ExitCode & " at " & p.ExitTime
                EmailAlert()
                PIMessage = "Exit Code = " & p.ExitCode & " at " & p.ExitTime
                p.Close()
            End Try

Open in new window


 Private Sub EmailAlert()
        Dim myEmail As New MailMessage()

        myEmail.From = New MailAddress("email@myemail.com")
        myEmail.To.Add("me@myemail.com")
        myEmail.Subject = EmailSubject
        myEmail.Body = EmailMessage
        myEmail.Priority = MailPriority.High

        Dim smtp As New SmtpClient("mysmtpclient")

        smtp.Send(myEmail)

    End Sub

Open in new window


Thank you for getting me this far.  Now I need to set up the task.  I will follow your instructions sedgwick and let you know how it went.

One question, I am using clickonce to deploy the program.  What is the best way to call the program from the task scheduler.  Or is it possible using this method to deploy it?
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38779136
Run the following in the command prompt:
Schtasks /create /tn "task-name" /sc daily /tr "your-vb.net.exe-path"  /st 00:00:00

Change task name to whatever u want and the exe path.
/st is when the task is running, currently is midnight.
0
 

Author Comment

by:McGurk1
ID: 38779342
Thanks for the quick response.  I do understand what you have written.  However, using clickOnce deployment the only exe is the setup.exe.  Doesn't seem like this is what is needed to run...   will have to research it more before testing it.
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 38779584
i didn't know there's a setup.exe, so u need to run the setup.exe first which deploy the vb.net application?
and after that to create the task scheduler?
0
 

Author Closing Comment

by:McGurk1
ID: 38779616
Found it is possible to use ClickOnce using the Start Menu properties string for that program.
See Eli Gazit's response that is the selected answer on the forum's question.  The Task Scheduler adds the additional information to this string automatically.
http://social.msdn.microsoft.com/forums/en-US/winformssetup/thread/a7b251b1-c9c4-438d-bce0-6b2ec46886c2/
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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