Hi Dino,
Thanx a million, it worked. One more query, if the
script takes a long time to process do i need to do any
special settings. Also i need soome good tutorials on
System.Diagnostics.Process.
Thanx
Prasad
-----Original Message-----
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
+ said:
}
}
</script>
<body>
<h3>Start Process (Test)</h3>
<h6>This page is running as
<%= System.Security.Principal.WindowsIdentity.GetCurrent ().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>
.