Hey Prasad, You can do it,
but you need to grant the right permissions to the ASP.NET identity,
OR
you need to run as some other identity. ASPNET by default does not have
permissions to start a process.
You can do the latter (run as a different identity) either using an
<impersonate .../> clause in web.config,
or by modifying machine.config to allow aspnet_wp.exe to use the system
identity. DANGER DANGER. Large flashing red lights and sirens!!! Do not
try this unless you know the risks!
Below is an example of the ASPX logic. I will not provide an example of how
to modify machine.config - you have to figure that out for yourself !
-Dino
=============== =============== =============== =========
<html>
<head>
<title>Test: Start Process in ASPX</title>
<link rel="stylesheet " href="style/basic.css"/>
</head>
<script language="C#" runat=server>
private string RunProcess(stri ng cmd) {
System.Diagnost ics.Process p;
p= new System.Diagnost ics.Process();
p.StartInfo.Fil eName= cmd;
p.StartInfo.Win dowStyle =
System.Diagnost ics.ProcessWind owStyle.Hidden;
p.StartInfo.Red irectStandardOu tput = true;
p.StartInfo.Use ShellExecute = false;
p.Start();
string output = p.StandardOutpu t.ReadToEnd();
p.WaitForExit() ;
return output;
}
public void Page_Load(Objec t Sender, EventArgs E) {
string command= Request.Params["cmd"];
if ((command == null) || (command == "")) {
ContentFromTheC ommand.Text= "No Command Specified.";
}
else {
String theOutput = RunProcess(comm and);
ContentFromTheC ommand.Text= "<xmp>" + theOutput + "</" + "xmp>";
}
}
</script>
<body>
<h3>Start Process (Test)</h3>
<h6>This page is running as
<%= System.Security .Principal.Wind owsIdentity.Get Current().Name %>
</h6>
<form id="form1" runat="server">
command to run: <asp:textbox id="cmd" name="cmd"
value="c:\cygwi n\bin\ls.exe" runat="server" columns="50" />
<br/>
<asp:button runat="server" Text="go!" />
</form>
<hr/>
<asp:label id="ContentFrom TheCommand" runat="server"/>
</body>
</html>
"Prasad" <p_*******@hotm ail.com> wrote in message
news:82******** *************** *****@phx.gbl.. .
Hi,
I have a batch file which does file manipulation, I need
to call this batch file using asp.net and display the o/p
of the command e.g the copy command o/p of the batch file
on the browser.
Is this possible. If yes can any one guide me for the same.
Thanx
Prasad