Use VB.NET to schedule DOS batch process

Posted on 2012-08-14
Last Modified: 2012-08-19
I need to run a dos batch process every 6 minutes - 8am Monday to 1800 Friday.

Within the (S999.BAT) batch file is 3 vb progs & an exec of FTP.
The process merges up to 20 files then checks to see that all records
are identical. Converts the merged audit file to html & FTP's the
page to the website.

The batch file -
mergeaudit C:\111\001\tempin1.txt C:\T111x001\mergeaudit.txt Y
mergeaudit C:\111\002\tempin1.txt C:\T111x001\mergeaudit.txt N
mergeaudit C:\111\003\tempin1.txt C:\T111x001\mergeaudit.txt N
mergeaudit C:\111\004\tempin1.txt C:\T111x001\mergeaudit.txt N
mergeaudit C:\111\005\tempin1.txt C:\T111x001\mergeaudit.txt N
.... up to 20 files
12checkaudit C:\T111x001\ T111x001
htmlgenc T111x001 _chkaudit.txt audit.html
FTP -i -s:ftpscript.txt

Run manually the batch file process works great.

I would like to execute this S999.BAT file scheduled as a VB.NET process.
I am not sure if I am even using the right processes as I have been doing
VB.NET very long.

This is a work in progress but so far I set the OKtorun flag on 1 minute
before the process start. Try to start the process and immediately turn
the flag off until the next schedule time.

The CMD exe window does open but does not execute any command!

I am sure there is a better way of doing this. Any help is appreciated.

Imports System
Imports System.IO
Imports System.Text
Imports System.Threading
Imports System.Diagnostics
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim OKtoRun As Boolean = False
            Dim number As Integer
            Dim moment As DateTime = DateTime.Now
            Dim minute As String = moment.Minute

            number = 1
            If OKtoRun = False Then
                If moment.Minute = "12" Then
                    OKtoRun = True
                End If
                If moment.Minute = "18" Then
                    OKtoRun = True
                End If
            End If
            If OKtoRun = True Then
                If moment.Minute = "11" Then
                    OKtoRun = False
                End If
                If moment.Minute = "12" Then
                    OKtoRun = False
                End If
            End If

        Catch ex As IOException
        End Try

    End Sub
End Class
Question by:EEA-Hove
    LVL 9

    Expert Comment

    This sounds more like, you need to create a windows service using multiple timers.  Here is somewhat of a background on it

    Author Comment

    Thanks Blue Yonder. I will look at it some more, but it is looking it a bit over my head!
    LVL 12

    Expert Comment

    If this is in Windows, you could just use the Task Scheduler to run the batch file.

    Author Comment

    Thanks Seaton007 but the Task scheduler is not that flexible. The batch file will be running 240 times a day.

    Accepted Solution

    I have just found the pycron scheduler ( which does what I need. Thanks for your suggestions. Wanted to persue VB.NET solution to increase my knowledge, but have already lost 36 hours dot netting, so onto the next bit of my project.

    Author Closing Comment

    The repetiton of running a BAT file every 6 minutes for 4 and half days was too much for Windows task scheduler. pycron does it accurately, and with a few clicks of the mouse. so will test it for a few days and hopefully job done.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    730 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

    15 Experts available now in Live!

    Get 1:1 Help Now