• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 544
  • Last Modified:

Use VB.NET to schedule DOS batch process

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
  • 4
1 Solution
This sounds more like, you need to create a windows service using multiple timers.  Here is somewhat of a background on it http://www.codeguru.com/vb/gen/vb_system/services/article.php/c4825/Creating-a-Windows-Service-in-VBNET.htm
EEA-HoveAuthor Commented:
Thanks Blue Yonder. I will look at it some more, but it is looking it a bit over my head!
If this is in Windows, you could just use the Task Scheduler to run the batch file.
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

EEA-HoveAuthor Commented:
Thanks Seaton007 but the Task scheduler is not that flexible. The batch file will be running 240 times a day.
EEA-HoveAuthor Commented:
I have just found the pycron scheduler (kalab.com) 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.
EEA-HoveAuthor Commented:
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now