65.9K
CodeProject is changing. Read more.
Home

Delete obsolete SMS clients

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.20/5 (3 votes)

Jan 13, 2007

GPL3
viewsIcon

25162

downloadIcon

428

An easy way to delete all the obsolete SMS clients...

Sample Image - DeleteObsoleteSMSClients.jpg

Introduction

Deleting the obsolete SMS clients can really be a pain in the ass. Especially at environments where a few 100 SMS clients get obsolete every day.

Using the code

  • Start up the application.
  • Issue the computername of the SMS server and the SMS Site Code.
  • Click on query to search for obsolete SMS clients.
  • Click on delete to delete the found obsolete SMS clients.

    I used the System.Management to query for and delete the obsolete SMS clients.

    Query for obsolete SMS clients:
    private void ThreadQueryObsolete()
    {
        ...       
    
        ManagementClass systemclass = new ManagementClass("SMS_R_System");
        ManagementScope oMs = new ManagementScope("\\\\" + tbxSMSServername.Text.Trim() + "\\root\\SMS\\Site_" + tbxSMSSiteCode.Text.Trim());
        systemclass.Scope = oMs;
    
        ObjectQuery oQuery = new ObjectQuery("SELECT ResourceId, NetbiosName FROM SMS_R_System WHERE Obsolete = 1");
    
        ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
        ManagementObjectCollection oReturnCollection = oSearcher.Get();
    
        foreach (ManagementObject oReturn in oReturnCollection)
        {
            string[] obsoletes = new string[2];
            obsoletes[0] = oReturn["ResourceId"].ToString();
            obsoletes[1] = oReturn["NetbiosName"].ToString();
            obsoleteList.Add(obsoletes);
            
            ListViewItem item = new ListViewItem(oReturn["NetbiosName"].ToString(), 0);
            SetListViewItems(item);
        }
    
        ...
    }
    
    Delete the obsolete SMS clients:
    private void ThreadDeleteObsolete()
    {
        ...       
    
        ManagementClass systemclass = new ManagementClass("SMS_R_System");
        ManagementScope oMs = new ManagementScope("\\\\" + tbxSMSServername.Text.Trim() + "\\root\\SMS\\Site_" + tbxSMSSiteCode.Text.Trim());
        systemclass.Scope = oMs;
        ManagementObject system = systemclass.CreateInstance();
    
        ObjectQuery oQuery = new ObjectQuery("SELECT ResourceId, NetbiosName FROM SMS_R_System WHERE ResourceId = '" + ((string[])obsoleteList[i])[0] + "' AND NetbiosName = '" + ((string[])obsoleteList[i])[1] + "' AND Obsolete = 1");
    
        ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
        ManagementObjectCollection oReturnCollection = oSearcher.Get();
    
        foreach (ManagementObject oReturn in oReturnCollection)
        {
            system["ResourceId"] = oReturn["ResourceId"].ToString();
            system.Delete();
        }
    
        ...
    }
    

    History

    Version 1.0 - Initial version.