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(string cmd) {
System.Diagnostics.Process p;
p= new System.Diagnostics.Process();
p.StartInfo.FileName= cmd;
p.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}
public void Page_Load(Object Sender, EventArgs E) {
string command= Request.Params["cmd"];
if ((command == null) || (command == "")) {
ContentFromTheCommand.Text= "No Command Specified.";
}
else {
String theOutput = RunProcess(command);
ContentFromTheCommand.Text= "<xmp>" + theOutput + "</" + "xmp>";
}
}
</script>
<body>
<h3>Start Process (Test)</h3>
<h6>This page is running as
<%= System.Security.Principal.WindowsIdentity.GetCurre nt().Name %>
</h6>
<form id="form1" runat="server">
command to run: <asp:textbox id="cmd" name="cmd"
value="c:\cygwin\bin\ls.exe" runat="server" columns="50" />
<br/>
<asp:button runat="server" Text="go!" />
</form>
<hr/>
<asp:label id="ContentFromTheCommand" runat="server"/>
</body>
</html>
"Prasad" <p_*******@hotmail.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