ASP.NET (VB.NET) : Execute batch file
There’s this interface application which requires the execution of batch file and it would need to be triggered when there is an action performed on the web form. While I was doing the coding, this execution process hits me and the code didn’t seems to execute as it should. I even coded the batch file to create an output file which contains some text and it worked out fine. Whereas the batch file that needs to be execute, having quite a number of rows in content, doesn’t want to work. The ASP.NET page just hanged there when executing the batch. The batch file is executed fine when it is manually triggered. This ponders me for sometime. I even tried using the vbscript (.vbs) which executes the batch file in hope it would workaround it but failed. It’s working fine if I manually runs it.
Without further ado, I searched around the net for some ideas. I found some bulletin posted on task scheduler which executes batch file via aspx pages. This came to me into using the scheduler to execute the batch file instead and apparently, it worked. Here, am going to share how I get it working.
I downloaded the library (taskscheduler.dll) from codeproject. The library generally encapsulates most of the function involves on task scheduler including creating, deleting, extracting and executing the task scheduler in Windows. Then referencing the library, I created a simple web form just to test it out if the batch file will get executed as expected, through scheduled job.
Dim st As ScheduledTasks = New ScheduledTasks(“\\pcname”)
Dim taskNames() As String = st.GetTaskNames()
Dim t As Task = st.OpenTask(“SchedulerJobName”)
t.Run()
The above code executes the “schedulerjobName” that was created to run the batch file. And the batch file did manage to run as expected.
That basically get my problem solved!
: )
Written by admin on May 3rd, 2010 with
no comments.
Read more articles on Programming.
- [+] Digg: Feature this article
- [+] Del.icio.us: Bookmark this article
- [+] Furl: Bookmark this article