Web Application Problem

Hi,

I would like to know how can I run a ".bat" file trough my web application, I tried using process but it doesn't get the argument...

Here is the part of the code..

System.Diagnostics.Process proc = new System.Diagnostics.Process();

proc.EnableRaisingEvents=false;

proc.StartInfo.FileName="C:\\Inetpub\\wwwroot\\Webshell\create.bat";

proc.StartInfo.Arguments="Pasta1 Pasta2";

proc.Start();

But it does not work, if I paste the command and the prompt it works fine..

Any help




Answer this question

Web Application Problem

  • aditya thatte

    Try calling the .bat from the cmd.exe

    proc.StartInfo.FileName= @"C:\Windows\system32\cmd.exe /C C:\Inetpub\wwwroot\Webshell\create.bat";

    and also setting the WorkingDirectory of StartInfo to "C:\Inetpub\wwwroot\Webshell\".
    I got some nasty behavior on executing processes in the past.Most of the times it's caused by missing properties that have to be initialized before calling the Start method.



  • Simon Clarke

    I tried this also Panagiotis Kefalidis but didn't work also...

  • GarfieldB

    I don't know how can I get it
    I just know that I'm using IIS(windows 2000) the full path to this app is "C:\Inetpub\wwwroot\Webshell\"

    Thanks for helping


  • parkfield

    I forgot to notice..In case it doesn't work after the code fix,check your Policy/Security Settings on the framework, about executing processes through Web Application Projects.Maybe there is a restriction on it.

  • Yento

    What's your Server.MapPath property value

  • timlajaunie

    Ok the only thing i can imagine now causing a problem is CAS (Code Access Security) and nothing more.. Check the settings there.
    Is there a chance that your IIS runs Chrooted (jailed to understand that his root is C:\inetpub\wwwroot and not C:\)

  • Harry Pfleger

    I've tried it already, sorry I didn't mention it returns an error : "The system cannot find the file specified"

    I've tried changing the names and some other things, but no success...

    The most strange is that in an Desktop application the first code works....(but shows the prompt and close automatically) but in a web don't !

  • guoliang12

    Thanks, for helping...but no success. I tried using your code, but I've got the same result !!!

    Any other



  • MadsNissen

    It returned c:\inetpub\wwwroot\


  • pascalh

    You're missing a \ at the end, before create.bat.
    To avoid confusion with escaping the slashes in C# , just put a @ in front of the string.@ means that the string is literal.Also set UseShellExecute property of StartInfo to true, as it's a command prompt.I'm not sure if it's make any difference, but i use it just in case.So your code is:

    System.Diagnostics.Process proc = new System.Diagnostics.Process();

    proc.EnableRaisingEvents=false;

    proc.UseShellExecute = true;

    proc.StartInfo.FileName= @"C:\Inetpub\wwwroot\Webshell\create.bat";

    proc.StartInfo.Arguments="Pasta1 Pasta2";

    proc.Start();

    Thanx,
    Giz.-



  • AVI13

    string path = Server.MapPath("/");

    that will give the stirng path the Root Folder path, which is your actuall working dir.

  • Web Application Problem