次の方法で共有


AdminProxy Class

 

Applies To: Windows Server Update Services

This class provides a starting point for getting an IUpdateServer, which is used to communicate with the WSUS server.

Namespace:   Microsoft.UpdateServices.Administration
Assembly:  Microsoft.UpdateServices.Administration (in Microsoft.UpdateServices.Administration.dll)

Inheritance Hierarchy

System.Object
  Microsoft.UpdateServices.Administration.AdminProxy

Syntax

[GuidAttribute("6391AFBB-45A8-4107-A154-F27DB8F03049")]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
public sealed class AdminProxy
[GuidAttribute("6391AFBB-45A8-4107-A154-F27DB8F03049")]
[ClassInterfaceAttribute(ClassInterfaceType::None)]
[ComVisibleAttribute(true)]
public ref class AdminProxy sealed 
[<Sealed>]
[<GuidAttribute("6391AFBB-45A8-4107-A154-F27DB8F03049")>]
[<ClassInterfaceAttribute(ClassInterfaceType.None)>]
[<ComVisibleAttribute(true)>]
type AdminProxy = class end
<GuidAttribute("6391AFBB-45A8-4107-A154-F27DB8F03049")>
<ClassInterfaceAttribute(ClassInterfaceType.None)>
<ComVisibleAttribute(True)>
Public NotInheritable Class AdminProxy

Constructors

Name Description
System_CAPS_pubmethod AdminProxy()

Initializes a new instance of the AdminProxy class.

Methods

Name Description
System_CAPS_pubmethod Equals(Object)

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Object.)

System_CAPS_pubmethod GetRemoteUpdateServerInstance(String, Boolean, Int32)

Connects to the specified remote WSUS server.

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_static GetUpdateServer()

Gets an IUpdateServer object that represents the local WSUS server.

System_CAPS_pubmethodSystem_CAPS_static GetUpdateServer(String, Boolean)

Gets an IUpdateServer that represents a remote WSUS server of the given name.

System_CAPS_pubmethodSystem_CAPS_static GetUpdateServer(String, Boolean, Int32)

Gets an IUpdateServer that represents a remote WSUS server of the given name on the given port.

System_CAPS_pubmethod GetUpdateServerInstance()

Gets an IUpdateServer object that represents a local WSUS server.

System_CAPS_pubmethod ToString()

(Inherited from Object.)

Remarks

AdminProxy has both static (shared in Visual Basic) and non-static methods for getting a IUpdateServer. If you use any of the static GetUpdateServer methods to retrieve an interface to the WSUS server, you will not have to instantiate an instance of AdminProxy. However, if you use the non-static GetUpdateServerInstance method, then you must use the new keyword to create an instance of AdminProxy.

Important

This class is not thread safe.

Examples

The following is an example in Visual Basic of the use of one of the static (shared in Visual Basic) methods to get an IUpdateServer representing a local WSUS server.

Dim iUpdateServer as IUpdateServer
iUpdateServer = AdminProxy.GetUpdateServer

The following is an example in Visual Basic of the use of the non-static method to get a IUpdateServer representing a local WSUS server.

Dim iUpdateServer as IUpdateServer
Dim proxy as New AdminProxy
iUpdateServer = AdminProxy.GetUpdateServer
/*----------------------------------------------------------------------
This file is part of the Microsoft Windows Server Update Services
API Code Samples.

Copyright (C) Microsoft.  All rights reserved.

DISCLAIMER OF WARRANTY: THIS CODE AND INFORMATION ARE PROVIDED “AS-IS.”  
YOU BEAR THE RISK OF USING IT.  MICROSOFT GIVES NO EXPRESS WARRANTIES, 
GUARANTEES OR CONDITIONS.  YOU MAY HAVE ADDITIONAL CONSUMER RIGHTS 
UNDER YOUR LOCAL LAWS WHICH THIS AGREEMENT CANNOT CHANGE.  
TO THE EXTENT PERMITTED UNDER YOUR LOCAL LAWS, MICROSOFT EXCLUDES 
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
PURPOSE AND NON-INFRINGEMENT.
----------------------------------------------------------------------*/

namespace WsusSamples
{
  using System;
  using System.Xml;

  using Microsoft.UpdateServices.Administration;

  class DetermineUpdateStatusForAllComputers
  {
    static void Main(string[] args)
    {
      const string usage = "\r\n" +
                            "ComputerStatusToXml. Creates an XML file with a list computers on the Update Services server, " +
                            "and the status of updates approved for each computer." +
                            "\r\n\r\n" +
                            "USAGE:" +
                            "\r\n\r\n" +
                            "    ComputerStatusToXml.exe [IncludeDownstreamComputers]" +
                            "\r\n\r\n" +
                            "        IncludeDownstreamComputers: Include computer targets rolled up from downstream servers." +
                            "\r\n";

      // evaluate args
      bool includeDownstreamComputers = false;
      if (args.Length >= 1)
      {
        if (args.Length > 1 || args[0].ToLower() != "includedownstreamcomputers")
        {
          Console.WriteLine(usage);
          return;
        }
        if (args[0].ToLower() == "includedownstreamcomputers")
        {
          includeDownstreamComputers = true;
        }
      }

      XmlTextWriter xml = null;

      try
      {
        Console.WriteLine("Getting computer status...");

        // open the XML file
        string xmlWriterFile = string.Format("{0}{1}{2}{3}",
                                              Environment.CurrentDirectory.ToString(),
                                              "\\ComputerStatus ",
                                              DateTime.Now.ToLongDateString().ToString(),
                                              ".xml");
        xml = new XmlTextWriter(xmlWriterFile, System.Text.Encoding.UTF8);
        xml.Formatting = Formatting.Indented;
        xml.Indentation = 4;

        xml.WriteStartDocument(true);
        xml.WriteStartElement("ComputerStatus");


        // Connect to the local WSUS server
        IUpdateServer updateServer = AdminProxy.GetUpdateServer();

        // Get the collection of computers on this server
        ComputerTargetScope computerTargetScope = new ComputerTargetScope();
        computerTargetScope.IncludeDownstreamComputerTargets = includeDownstreamComputers;
        ComputerTargetCollection computers = updateServer.GetComputerTargets(computerTargetScope);

        // loop through the computer collection 
        foreach (IComputerTarget computer in computers)
        {
          // start the element for the computer
          xml.WriteStartElement("Computer");
          xml.WriteAttributeString("Name", computer.FullDomainName);

          xml.WriteAttributeString("LastReportedStatus", computer.LastReportedStatusTime.ToString());

          if (includeDownstreamComputers == true)
          {
            string parentName = "LocalHost";
            if (computer.ParentServerId != Guid.Empty)
            {
              parentName = computer.GetParentServer().FullDomainName;
            }
            xml.WriteAttributeString("ParentServer", parentName);
          }

          // start the element for the status of updates on this computer
          xml.WriteStartElement("UpdateStatus");

          // get the install state of all updates approved for this computer
          UpdateInstallationInfoCollection installStatus = computer.GetUpdateInstallationInfoPerUpdate();

          // loop through the updates in the install info collection and output the 
          // name of the update and it's install state on this computer
          foreach (IUpdateInstallationInfo updateStatus in installStatus)
          {
            xml.WriteStartElement("Update");
            xml.WriteAttributeString("Title", updateStatus.GetUpdate().Title);
            xml.WriteAttributeString("Status", updateStatus.UpdateInstallationState.ToString());

            // close the Update element
            xml.WriteEndElement();
          }

          // close the UpdateStatus element
          xml.WriteEndElement();

          // close the Computer element
          xml.WriteEndElement();
        } // foreach

      } //try
      catch (Exception)
      {
      } // catch
      finally
      {
        Console.WriteLine("Done. Results are written to the ComputerStatus {0}.xml file in the current folder",
                          DateTime.Now.ToLongDateString());
        xml.Close();
      } // finally
    } // main
  }
          }

Thread Safety

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Microsoft.UpdateServices.Administration Namespace

Return to top