How to execute a batch file from an asp+ script
Can't seem to figure out how to execute a batch file from an asp+ script
the Shell command works but seemingly only for gui based non-command
line apps i.e. calc.exe or notepad.exe but not for cmd.exe
Any clues?
# 1 Re: How to execute a batch file from an asp+ script
Hi Tom,
I tried the following and it works and I my guess was it should not
work(the security thing, winstations and ability to interact with the
interactive desktops -- I checked again and again to make sure my services
were started in default system account without itneraction with the
desktop..so I am surprised that this works)
The batch file is test.bat and present in a given directory. If you don't
provide working directory default path is taken(winnt/system32).
Try this if it does not work, you may have to work on doing security
stuff(impersonating another user etc) for starting the process...
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Diagnostics" %>
<html>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E ) {
String appName = "test.bat";
String executableFilename = appName ;
Process pr = new Process();
pr.StartInfo.FileName = executableFilename;
pr.StartInfo.WorkingDirectory = "D:\\Projects\\ngws\\aspx\\process";
// pr.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Minimized;
pr.WatchForExit = true;
try{
pr.Start();
// pr.WaitForExit(500);
while (!pr.HasExited)
;
Response.Write(pr.ExitCode.ToString());
}
catch ( Exception e )
{
Response.Write(e.Message);
Response.Write(e.Source);
Response.Write(e.StackTrace);
}
}
</script>
</html>
"Tom Ashworth" <tomash@bellsouth.net> wrote in message
news:39b1a8b1$1@news.dev-archive.com...
> Can't seem to figure out how to execute a batch file from an asp+ script
> the Shell command works but seemingly only for gui based non-command
> line apps i.e. calc.exe or notepad.exe but not for cmd.exe
>
> Any clues?
>
>