user1104946
user1104946

Reputation: 690

trying to open iis in windows form

I am using below code to start IIS in Windows Form.

if (hWndDocked != IntPtr.Zero) //don't do anything if there's already a window docked.
    return;

hWndParent = IntPtr.Zero;

pDocked = Process.Start(@"C:\Windows\System32\inetsrv\inetmgr");
while (hWndDocked == IntPtr.Zero)
{
    pDocked.WaitForInputIdle(1000); //wait for the window to be ready for input;
    pDocked.Refresh();              //update process info
    if (pDocked.HasExited)
    {
        return; //abort if the process finished before we got a handle.
    }
    hWndDocked = pDocked.MainWindowHandle;  //cache the window handle
}
//Windows API call to change the parent of the target window.
//It returns the hWnd of the window's parent prior to this call.
hWndOriginalParent = SetParent(hWndDocked, panel1.Handle);

//Wire up the event to keep the window sized to match the control
panel1.SizeChanged += new EventHandler(Panel1_Resize);
//Perform an initial call to set the size.
Panel1_Resize(new Object(), new EventArgs());

But I am getting error:

the system cannot find the file

But the same thing works for notepad.

Upvotes: 0

Views: 372

Answers (1)

Brugner
Brugner

Reputation: 747

I had the same issue and the only way I found was this:

Process.Start(Environment.SystemDirectory + "\\inetsrv\\iis.msc");

I hope it helps!

Upvotes: 2

Related Questions