0

I am automating some batch files into a single C# application but not having much luck. I have the following batch file (and another 3) that I am trying to write in C#

"C:\Program Files\IIS Express\iisexpress.exe" /path:c:\windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles /vpath:"/asp.netwebadminfiles" /port:61569 /clr:4.0 /ntlm

Here is the C# code I have found online but it fails:

using (Process proc = new Process())
{
    proc.StartInfo.FileName = "iisexpress.exe";
    proc.StartInfo.Arguments = @"/path:c:\windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles /vpath:/asp.netwebadminfiles /port:61569 /clr:4.0 /ntlm";
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.Start();
    proc.WaitForExit();
    Console.Out.WriteLine(proc.StandardOutput.ReadToEnd());
}

I get the following, with no help from Google:

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll

3
  • Add quotes around the parameter values? @"/path:""c:\windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles"" /vpath:""/asp.netwebadminfiles"" /port:61569 /clr:4.0 /ntlm" Commented Sep 23, 2014 at 13:36
  • 1
    What does the exception message say? Commented Sep 23, 2014 at 13:37
  • @YuvalItzchakov Exception:Thrown: "The system cannot find the file specified" (System.ComponentModel.Win32Exception) A System.ComponentModel.Win32Exception was thrown: "The system cannot find the file specified" Commented Sep 23, 2014 at 14:15

1 Answer 1

4

You need to give Process.StartInfo.FileName the full path to your exe:

proc.StartInfo.FileName = @"C:\Program Files\IIS Express\iisexpress.exe";
Sign up to request clarification or add additional context in comments.

2 Comments

I tried this and did not get an error, but the command window appeared with no text. Does it mean it is still working in the background? Sorry for my lack of knowledge.
I've tested this using LINQPad and i see the site registered properly. Check your IIS configuration to make sure it worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.