我正在寻找很多方法来获取.NET中的父进程,但只找到了P/Invoke方式.
我正在尝试在C#中构建一个小应用程序,它应该启动/停止IIS Express工作进程.为此,我想使用MSDN上记录的官方"IIS Express API":http://msdn.microsoft.com/en-us/library/gg418415.aspx
据我所知,API仅(仅)基于COM接口.为了使用这个COM接口,我通过Add Reference - > COM - >"IIS Installed Versions Manager Interface"在VS2010中添加了对COM库的引用:

到目前为止一切都很好,但下一步是什么?有一个IIISExprProcessUtility可用的接口,包括启动/停止IIS进程的两个"方法".我是否必须编写一个实现此接口的类?
public class test : IISVersionManagerLibrary.IIISExprProcessUtility
{
public string ConstructCommandLine(string bstrSite, string bstrApplication, string bstrApplicationPool, string bstrConfigPath)
{
throw new NotImplementedException();
}
public uint GetRunningProcessForSite(string bstrSite, string bstrApplication, string bstrApplicationPool, string bstrConfigPath)
{
throw new NotImplementedException();
}
public void StopProcess(uint dwPid)
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我不是一名专业开发人员.有人能指出我正确的方向.任何帮助是极大的赞赏.
更新1: 根据建议,我尝试了下面的代码,但遗憾的是它不起作用:
好的,它可以实例化但我看不到如何使用这个对象...


IISVersionManagerLibrary.IIISExpressProcessUtility test3 = (IISVersionManagerLibrary.IIISExpressProcessUtility) Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("5A081F08-E4FA-45CC-A8EA-5C8A7B51727C")));
Exception: Retrieving the …Run Code Online (Sandbox Code Playgroud) 我的C#代码可能在IIS下的MVC3应用程序内运行(目前为7.5,但我不想依赖于特定版本)或其他地方.
看起来知道代码在IIS下运行的一种方法是检查当前进程名称,但这种方法取决于硬编码的文件名字符串.
是否有一些编程方式来检测我的代码是否在IIS下运行而不依赖于IIS版本?
我想从代码隐藏文件中找到IIS ASP.NET Web服务器上给定文件扩展名的mime类型.
我想搜索服务器本身在提供文件时使用的相同列表.这意味着将包含Web服务器管理员添加到Mime Map的任何mime类型.
我可以盲目地使用
HKEY_CLASSES_ROOT\MIME\Database\Content Type
Run Code Online (Sandbox Code Playgroud)
但是没有记录为IIS使用的列表,也没有记录存储Mime Map的位置.
我可以盲目地调用FindMimeFromData,但是没有记录为IIS使用的相同列表,也不能保证IIS Mime Map也将从该调用返回.
c# ×3
iis ×3
asp.net ×1
asp.net-mvc ×1
com ×1
com-interop ×1
iis-express ×1
managed ×1
mime ×1
mime-types ×1
parent ×1
pinvoke ×1
process ×1