.Net 获取远程IIS 的web applications 代码片段

来源:互联网 发布:html windows.onload 编辑:程序博客网 时间:2024/05/17 06:54

string pool = "W3SVC/AppPools/";

 

           

List<string> result = newList<string>();

 

           

ConnectionOptions co = newConnectionOptions();

 

            co.Username =

@"xxx";

 

            co.Password =

@xxx";

 

            co.Authentication =

AuthenticationLevel.PacketPrivacy;

 

           

ManagementScope scope = newManagementScope(@"\\" + serverIP/machinename +@"\root\MicrosoftIISV2", co);

 

           

ObjectQuery query = newObjectQuery(string.Format("SELECT * FROM IIsApplicationPool"));

 

           

ManagementObjectSearcher searcher = newManagementObjectSearcher(scope, query);

 

           

foreach (ManagementBaseObject mo in searcher.Get())

 

            {

               

string name = (string)mo.Properties["Name"].Value;

 

                result.Add(name.Substring(pool.Length));

            }

 

原创粉丝点击