SCCM 2012 Console Extension: WqlConnectionManager and SmsNamedValuesDictionary

Hi,

For a console extension, I need to connect to the site server.  Since the extension is running inside the console (i.e. it is already connected to a site server), how do I get the siteserver name so that I do not need to instantiate the WqlConnectionManager and have to feed it the sitename, userid and password.  My point here is that the extension would not be loaded if a valid connection to the site server did not exist.  So the classic connection example code always makes you create a WqlConnectionManager and have to pass credentials.  This would be really inconvenient to the end-user and make the console extension frustrating to use.  I thought that the SmsNamedValuesDictionary would contain all the "##SUB" properties like ADSiteName (which is what I need to feed into the WqlConnectionManager contructor) but it is empty.

Below is the code I am using (which is what all the examples are using).  So to beat a dead horse, the console exentsion assembly would not be properly loaded if a valid connection to a site server did not exist so how can I reuse (in my code) the valid connection?  Hope this makes sense.  Thanks in advance.

private bool ConnectToSCCM(string stringServerName_in,
                                   string stringUserName_in,
                                   string stringPassword_in)
        {
            bool l_boolConnectedToSCCM = false;

            try
            {
//##SUB:ADSiteName##

                SmsNamedValuesDictionary namedValues = new SmsNamedValuesDictionary();
                m_WqlConnectionManager = new WqlConnectionManager(namedValues);
                if (System.Net.Dns.GetHostName().ToUpper() == stringServerName_in.ToUpper())
                {
                    m_WqlConnectionManager.Connect(stringServerName_in);
                }
                else
                {
                    m_WqlConnectionManager.Connect(stringServerName_in, stringUserName_in, stringPassword_in);
                }

                l_boolConnectedToSCCM = true;
            }
            catch (SmsException ex)
            {
                MessageBox.Show("Failed to connect to SCCM. Error: " + ex.Message);
            }
            catch (UnauthorizedAccessException ex)
            {
                MessageBox.Show("Failed to authenticate to SCCM. Error:" + ex.Message);
            }

            return (l_boolConnectedToSCCM);
        }		
August 2nd, 2013 9:08pm

Hi,

For anyone else who might be looking for an answer...

If you look at the Microsoft page "How to Create a Configuration Manager Console Custom View", in the EndInit method, you can get an instance of a WqlConnection.  I made _m_WqlConnectionManager a static public variable to the console extension namespace so I can get at it in downstream classes/instances.

public override void EndInit()
{            
  base.EndInit();

  _m_WqlConnectionManager = 
  (WqlConnectionManager)base.ConnectionManager;

  this.Content = new Label() { Content = "My Content" };
}

Free Windows Admin Tool Kit Click here and download it now
August 9th, 2013 1:30pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics