Okay, rubbing the EmpegBBS lamp once again, as Google is running me in circles.
I have a test where my C# code is running a test version of the company web site under IIS
Express. I have a requirement that I need to, on demand,
gracefully stop the web site to end the test. By gracefully, I mean, it cannot be TaskKill'ed or else that would ruin the test. (Specifically, if the task is not exited gracefully with a 0 exit code, the code coverage tool doesn't collect code coverage for the site, and the code coverage is the thing that I want.)
The site is launched from the IIS express command line tool like this:
iisexpress.exe /trace:info /path:C:\development\code\sites\websitename /port:5150
This works, and, if I were lucky enough to be on the same machine that is running the test and could get to the console window, simply pressing the Q key would stop the web site gracefully and do exactly what I want.
Problems:
- The site, and the test that controls the site, is running on servers without an active login. So finding the console window, focusing it, and doing a window-based "SendKeys" to that window is not an option.
- I don't actually need a window and a login to do console I/O redirection. That's worked for me before in the past. But in this case, though I can easily launch the iisexpress process myself from my C# code and control its console I/O, it does not respond to the following command:
IisExpressProcess.StandardInput.Write("q"); // WriteLine also does not work
I've successfully done that same thing to other processes (to other console apps in the same test group in fact), and I'm doing all of the same steps to make that happen. Normally other console programs respond to that just fine. IISExpress is behaving differently. As if it's not using a standard way of getting its keyboard input from stdin. Maybe it's doing some sort of keyscan code polling or something. Not sure.
Okay, so then I look at other ways to stop the site gracefully. 99 percent of the search results say to taskkill the site. The few that seem to start to be helpful say things like:
- There's a powershell script that does it: Stop-WebSite 'websitename'
- But you have to install/import the correct powershell website management module to get that work:
Add-PSSnapin WebAdministration
Import-Module WebAdministration
- But those don't work for me. So the internet says to install the module from the download of that module at the MSDN web site.
- It's here that I discover that it's a module for full IIS 7.0 and not for IIS express. It won't even let me install the thing.
- There are other places that say to go to Add/RemovePrograms and hit "Windows Features" and install the management module from there. But looking at those menus, that's also for full IIS and not for IIS express. And anyway it's not clear which tickybox to tick even.
- Okay, then other places say, oh, it's easy, there's a command line tool in the IIS express folder called "appcmd" and it'll let you do a STOP SITE command. Example:
appcmd stop site /site.name: Websitename
- That DOES NOT WORK. Appcmd responds that this is an invalid command, there is no such command as "STOP" for a "SITE". So somehow the version of appcmd I've got is nerfed somehow. Again, this might be an IIS Express versus Full IIS problem. Not sure.
- All the other options I'm seeing (vbscript and WMI methods) all hark back to that website management module. Which I can't figure out how to get installed or whether it even functions with IIS express at all.
Phew.
Any ideas anyone? Please help!