execute batch file

G

Guest

Hi,
How can I execute a batch file form asp.net app. I have a form which a user
uploads a text file. after the file is uploaded I want a batch file to then
execute and do some work.

Thanks
 
G

Guest

It depends on whether the upload triggers or something else. There are a
couple of ways I can think of to handle this:

1. Use a Process object to process the file when the upload is finished.
2. Create a service that uses a FileWatcher to watch for files to be
processed that processes when a new file appears. This is not driven by the
ASP.NET page.
3. Create a process that runs every once in awhile to see if there are
unprocessed files. Use a scheduler to run it. This is similar to #2, but does
not require learning how to use the FileWatcher.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
S

Steve C. Orr [MVP, MCSD]

This code should do the trick:

Dim myprocess As System.Diagnostics.Process = New
System.Diagnostics.Process()
myprocess.StartInfo.FileName = "c:\SomeFile.bat"
myprocess.StartInfo.WorkingDirectory = "C:\"
myprocess.StartInfo.Arguments= " file.txt -s -m"
myprocess.Start()

If you run into security problems you might try using impersonation to run
ASP.NET under a user account that has more permissions than the standard
ASPNET user account.

Here's more info on impersonation:
http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconaspnetimpersonation.asp
 
G

Guest

beautiful!

Steve C. Orr said:
This code should do the trick:

Dim myprocess As System.Diagnostics.Process = New
System.Diagnostics.Process()
myprocess.StartInfo.FileName = "c:\SomeFile.bat"
myprocess.StartInfo.WorkingDirectory = "C:\"
myprocess.StartInfo.Arguments= " file.txt -s -m"
myprocess.Start()

If you run into security problems you might try using impersonation to run
ASP.NET under a user account that has more permissions than the standard
ASPNET user account.

Here's more info on impersonation:
http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconaspnetimpersonation.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top