[英]How do i reset IIS remotely using C#.Net code?
I have the IIS service running on Windows Server 2008 and i want to reset it from my windows 7 machine . 我在Windows Server 2008上运行IIS服务,我想从我的Windows 7机器重置它。
How do i reset IIS remotely using C#.Net code? 如何使用C#.Net代码远程重置IIS?
I tried using Microsoft.Web.Administration, but it doesn't accept remote server details to connect to .Any other API's that can be used for this purpose ? 我尝试使用Microsoft.Web.Administration,但它不接受远程服务器详细信息连接到。可以用于此目的的其他API吗?
If you have a specific web site name, you can use the WMI to stop and start that web site. 如果您有特定的网站名称,则可以使用WMI来停止和启动该网站。 If it's IIS as a whole, I'm sure there is something in the IIS WMI provider for doing this.
如果它是IIS的整体,我确信IIS WMI提供程序中有一些东西可以做到这一点。 Here I'm using WebAdministration to manage a web site under IIS, but there's also MicrosoftIISV2.
在这里,我使用WebAdministration管理IIS下的网站,但也有MicrosoftIISV2。 Google for WmiExplorer, there are some good ones out there.
谷歌为WmiExplorer,那里有一些好的。
var connOptions = new ConnectionOptions();
connOptions.Authentication = AuthenticationLevel.PacketPrivacy;
// if you want to connect as someone other than logged in user
//connOptions.Username = username;
//connOptions.Password = password;
var scope = new ManagementScope("\\localhost\WebAdministration", connOptions);
WqlObjectQuery query = new WqlObjectQuery(`enter code here`string.Format("SELECT * FROM Site WHERE Name = '{0}'", "Default Web Site"));
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
{
foreach (ManagementObject site in searcher.Get())
{
ManagementBaseObject inParams = site.GetMethodParameters("Stop");
site.InvokeMethod("Stop", inParams, null);
ManagementBaseObject inParams2 = site.GetMethodParameters("Start");
site.InvokeMethod("Start", inParams2, null);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.