试图以Windows窗体打开iis

时间:2016-06-24 14:01:17

标签: c# forms winforms webforms

我使用下面的代码在Windows窗体中启动IIS。

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());

但我收到错误:

  

系统无法找到文件

但同样的事情适用于记事本。

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,我找到的唯一方法是:

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

我希望它有所帮助!