Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C#, Authenticate to WSUS

C#, Authenticate to WSUS

Scheduled Pinned Locked Moved C#
csharpquestionlinqsysadminjson
4 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AGTCooke
    wrote on last edited by
    #1

    Hey all - I'm a total newb, and I'm trying to use the WSUS API to connect to a specified WSUS Server and "do stuff". The problem is that it currently uses the currently logged on use to connect to the WSUS server, which fails. If I do a "run as" on the program, and use the correct credentials, it works. So, the question is how to prompt for credentials (command line) and connect to the WSUS server?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    using Microsoft.UpdateServices;
    using Microsoft.UpdateServices.Administration;

    namespace WSUS_Check
    {
    class Program
    {
    static void Main(string[] args)
    {
    //--- Vars ---//
    string Server;
    int Port, ans, count;
    bool Secure;
    ArrayList TGIDs;

            //--- Header ---//
            System.Console.WriteLine("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");
            System.Console.WriteLine("Custom WSUS Check, v0.01");
            System.Console.WriteLine("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");
            System.Console.WriteLine();
    
            //--- Get connection information ---//
            System.Console.Write("WSUS Server: ");
            Server = System.Console.ReadLine();
            System.Console.Write("Port: ");
            Port = int.Parse(System.Console.ReadLine());
    
            do
            {
                System.Console.Write("Secure \[1\\\\0\]: ");
                ans = int.Parse(System.Console.ReadLine());
            } while ( (ans != 1) && (ans != 0) );
    
            if (ans == 1)
            {
                Secure = true;
            }
            else
            {
                Secure = false;
            }
            
            //--- Connect to the specified WSUS Server ---//
            IUpdateServer Host;
            try
            {
                Host = AdminProxy.GetUpdateServer(Server, Secure, Port);
                
                //--- Working Section for Auth ---//
                
                
    
    
                //--- End working section for Auth ---//
                
                System.Console.WriteLine("Connected to " + Host.Name.ToString() + " \[WSUS v. " + Host.Version.ToString() + "\]");
                System.Console.WriteLine();
    
                //--- Enumerate Groups ---//
                S
    
    K 1 Reply Last reply
    0
    • A AGTCooke

      Hey all - I'm a total newb, and I'm trying to use the WSUS API to connect to a specified WSUS Server and "do stuff". The problem is that it currently uses the currently logged on use to connect to the WSUS server, which fails. If I do a "run as" on the program, and use the correct credentials, it works. So, the question is how to prompt for credentials (command line) and connect to the WSUS server?

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Collections;
      using Microsoft.UpdateServices;
      using Microsoft.UpdateServices.Administration;

      namespace WSUS_Check
      {
      class Program
      {
      static void Main(string[] args)
      {
      //--- Vars ---//
      string Server;
      int Port, ans, count;
      bool Secure;
      ArrayList TGIDs;

              //--- Header ---//
              System.Console.WriteLine("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");
              System.Console.WriteLine("Custom WSUS Check, v0.01");
              System.Console.WriteLine("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");
              System.Console.WriteLine();
      
              //--- Get connection information ---//
              System.Console.Write("WSUS Server: ");
              Server = System.Console.ReadLine();
              System.Console.Write("Port: ");
              Port = int.Parse(System.Console.ReadLine());
      
              do
              {
                  System.Console.Write("Secure \[1\\\\0\]: ");
                  ans = int.Parse(System.Console.ReadLine());
              } while ( (ans != 1) && (ans != 0) );
      
              if (ans == 1)
              {
                  Secure = true;
              }
              else
              {
                  Secure = false;
              }
              
              //--- Connect to the specified WSUS Server ---//
              IUpdateServer Host;
              try
              {
                  Host = AdminProxy.GetUpdateServer(Server, Secure, Port);
                  
                  //--- Working Section for Auth ---//
                  
                  
      
      
                  //--- End working section for Auth ---//
                  
                  System.Console.WriteLine("Connected to " + Host.Name.ToString() + " \[WSUS v. " + Host.Version.ToString() + "\]");
                  System.Console.WriteLine();
      
                  //--- Enumerate Groups ---//
                  S
      
      K Offline
      K Offline
      KaptinKrunch
      wrote on last edited by
      #2

      Since this is a console app, you could just create a batch file to run your program as who ever with the runas command. That way you don't need to have have to modify your code.

      Just because we can; does not mean we should.

      A 1 Reply Last reply
      0
      • K KaptinKrunch

        Since this is a console app, you could just create a batch file to run your program as who ever with the runas command. That way you don't need to have have to modify your code.

        Just because we can; does not mean we should.

        A Offline
        A Offline
        AGTCooke
        wrote on last edited by
        #3

        Sure, that's one way, but not the way I'd like to see it done. The code has to be modified anyways, midas well do it now. Plus I can learn the an auth. peice from this, which will be cool.

        M 1 Reply Last reply
        0
        • A AGTCooke

          Sure, that's one way, but not the way I'd like to see it done. The code has to be modified anyways, midas well do it now. Plus I can learn the an auth. peice from this, which will be cool.

          M Offline
          M Offline
          myname989
          wrote on last edited by
          #4

          Did you find a solution for this? I am facing the same problem. If you found a solution can you share the sample code.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups