Yeah, wow, this one is a real stumper.

I can get this to work in a local bench test by doing the following:

- Launch the IIS Express executable in a separate window.
- Do my tests to exercise the site.
- When the tests are done, Find the IIS Express Process.MainWindowHandle, then send it a PostMessage of WM_KEYDOWN and WM_KEYUP for the keycode for "q", which is what IIS Express needs to close down gracefully. (StandardInput.Write("q") does NOT work for IIS Express.)
- I can also in many cases successfully send WM_QUIT to the window, or, do TASKKILL /IM Iisexpress.exe.

All of the above things work on my local machine in a brief bench test but then fail utterly once I run the full test suite up on the Team City server. When I try to close down IIS express with these methods, it's ignoring the keystroke and/or refusing to close from the WM_QUIT message.

For instance, doing TASKKILL /IM IISExpress.exe, which works in a local bench test, fails with the following log output on Team City:

ERROR: The process "iisexpress.exe" with PID 3212 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process "iisexpress.exe" with PID 6268 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process "iisexpress.exe" with PID 6084 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process "iisexpress.exe" with PID 3348 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process "iisexpress.exe" with PID 3976 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
_________________________
Tony Fabris