/smsclictr.automation/SMSClient.cs
# · C# · 2523 lines · 903 code · 119 blank · 1501 comment · 52 complexity · 336bbab2d69dab737ea07272ba1e927a MD5 · raw file
Large files are truncated click here to view the full file
- //SCCM Client Center Automation Library (SMSCliCtr.automation)
- //Copyright (c) 2008 by Roger Zander
-
- //This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version.
- //This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- //GNU General Public License: http://www.gnu.org/licenses/lgpl.html
-
- using System;
- using System.Collections;
- using System.Management;
- using System.Runtime.InteropServices;
- using System.Collections.Generic;
-
- [assembly: CLSCompliant(false)]
- namespace smsclictr.automation
- {
- /// <summary>
- /// SMSClient automation main class
- /// </summary>
- public class SMSClient : IDisposable
- {
- #region Internal Settings
-
- private WMIProvider oWMIProvider;
- private ManagementObject mo_SMS_Authority;
- private string sSiteCode;
- private string sMP;
- private SMSSchedules oSMSSchedules;
- private WMIRegistry oWMIRegistry;
- private WMIService oWMIService;
- private CCMSoftwareDistribution oCCMSoftwareDistribution;
- private WindowsInstaller oMSI;
- private WMIFileIO oWMIFileIO;
- private WMIComputerSystem oCompSys;
- private SMSComponents oSMSComponents;
- private SCCMDCM oDCM;
- private ManagementObject oSMS_Client;
- private ManagementObject oCCM_Client;
- private ManagementObject oCacheConfig;
- internal string pHostname;
- internal string pUsername;
- internal string pPassword;
- internal string sSMSVersion = "";
- internal string sLocalSMSPath = "";
-
- #endregion
-
- #region Constructors
-
- /// <summary>
- /// SMSClient Constructor
- /// </summary>
- /// <param name="hostname">Hostname or IP-Address of the remote host</param>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// </code>
- /// </example>
- public SMSClient(string hostname)
- {
- connect(hostname, null, null);
- }
-
- /// <summary>
- /// SMSClient Constructor
- /// </summary>
- /// <param name="hostname">Hostname or IP-Address of the remote host</param>
- /// <param name="username">Username to Logon (Domain\User)</param>
- /// <param name="password">Password of the specified Username</param>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01", "Domain\SMSAdmin", "password");
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01", "Domain\SMSAdmin", "password")
- /// </code>
- /// </example>
- public SMSClient(string hostname, string username, string password)
- {
- connect(hostname, username, password);
- }
-
- /// <summary>
- /// SMSClient Constructor
- /// </summary>
- /// <param name="wmiProvider">WMIProvider</param>
- public SMSClient(WMIProvider wmiProvider)
- {
- connect(wmiProvider);
- }
-
- /// <summary>
- /// Connect the WMI Namespace root\cimv2 on a remote system
- /// </summary>
- /// <param name="sHostname">Hostname</param>
- protected void connect(string sHostname)
- {
- connect(sHostname, null, null);
- }
-
- /// <summary>
- /// Connect the WMI Namespace root\cimv2 on a remote system
- /// </summary>
- /// <param name="sHostname"></param>
- /// <param name="username"></param>
- /// <param name="password"></param>
- protected void connect(string sHostname, string username, string password)
- {
- oWMIProvider = new WMIProvider(@"\\" + sHostname + @"\ROOT\cimv2", username, password);
- connect(oWMIProvider);
- pHostname = sHostname;
- pUsername = username;
- pPassword = password;
- }
-
- /// <summary>
- /// Connect the WMI Namespace root\cimv2 on a remote system
- /// </summary>
- /// <param name="oProvider">WMI Provider</param>
- protected void connect(WMIProvider oProvider)
- {
- oWMIProvider = oProvider;
- oSMSSchedules = new SMSSchedules(oWMIProvider);
- oWMIRegistry = new WMIRegistry(oWMIProvider);
- oWMIService = new WMIService(oWMIProvider);
- oCCMSoftwareDistribution = new CCMSoftwareDistribution(oWMIProvider);
- oMSI = new WindowsInstaller(oWMIProvider);
- oWMIFileIO = new WMIFileIO(oWMIProvider);
- oCompSys = new WMIComputerSystem(oWMIProvider);
- oSMSComponents = new SMSComponents(oWMIProvider);
- oDCM = new SCCMDCM(oWMIProvider);
- }
-
- /// <summary>
- /// SMSSchedules Class
- /// </summary>
- public SMSSchedules Schedules { get { return oSMSSchedules; } }
-
- /// <summary>
- /// CCM_SoftwareDistribution Class
- /// </summary>
- public CCMSoftwareDistribution SoftwareDistribution { get { return oCCMSoftwareDistribution; } }
-
- /// <summary>
- /// WindowsInstaller Class
- /// </summary>
- public WindowsInstaller MSI { get { return oMSI; } }
-
- /// <summary>
- /// WMIFileIO Class
- /// </summary>
- public WMIFileIO FileIO { get { return oWMIFileIO; } }
-
- /// <summary>
- /// WMIComputerSystem Class
- /// </summary>
- public WMIComputerSystem ComputerSystem { get { return oCompSys; } }
-
- /// <summary>
- /// SMSComponents Class
- /// </summary>
- public SMSComponents Components { get { return oSMSComponents; } }
-
- /// <summary>
- /// SCCMDCM Class
- /// </summary>
- public SCCMDCM DCM { get { return oDCM; } }
-
- /// <summary>
- /// Cache the Object "root\ccm:SMS_Client"
- /// </summary>
- internal ManagementObject mSMS_Client
- {
- get
- {
- if ((oSMS_Client == null) | Reload)
- {
- WMIProvider oProv = new WMIProvider(oWMIProvider.mScope.Clone());
- oProv.mScope.Path.NamespacePath = @"ROOT\CCM";
- Reload = false;
- return oProv.GetObject("SMS_Client=@");
- }
- else
- return oSMS_Client;
- }
-
- set
- {
- oSMS_Client = value;
- }
- }
-
- /// <summary>
- /// Cache the Object "root\ccm:CCM_Client"
- /// </summary>
- internal ManagementObject mCCM_Client
- {
- get
- {
- if ((oCCM_Client == null) | Reload)
- {
- WMIProvider oProv = new WMIProvider(oWMIProvider.mScope.Clone());
- oProv.mScope.Path.NamespacePath = @"ROOT\CCM";
- Reload = false;
- return oProv.GetObject("CCM_Client=@");
- }
- else
- return oCCM_Client;
- }
-
- set
- {
- oCCM_Client = value;
- }
- }
-
- /// <summary>
- /// Cache the Object "root\ccm\SoftMgmtAgent:CacheConfig"
- /// </summary>
- internal ManagementObject mCacheConfig
- {
- get
- {
- if ((oCacheConfig == null) | Reload)
- {
- WMIProvider oProv = new WMIProvider(oWMIProvider.mScope.Clone());
- oProv.mScope.Path.NamespacePath = @"root\ccm\SoftMgmtAgent";
- Reload = false;
- return oProv.GetObject("CacheConfig.ConfigKey='Cache'");
-
- }
- else
- return oCacheConfig;
- }
-
- set
- {
- oCacheConfig = value;
- }
- }
-
- /// <summary>
- /// Do not use cached Object. Reload the Object (Once!)
- /// </summary>
- public bool Reload
- {
- get;set;
- }
-
- #endregion
-
- #region Puplic Properties
-
- /// <summary>
- /// Dispose
- /// </summary>
- public void Dispose()
- {
- oWMIProvider = null;
- GC.Collect();
- }
-
- /// <summary>
- /// Get or Set the assigned SMS SiteCode
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.SiteCode);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.SiteCode
- /// </code>
- /// </example>
- public string SiteCode
- {
- get
- {
- if (sSiteCode != null)
- return sSiteCode;
- else
- {
- WMIProvider oProv = new WMIProvider(oWMIProvider.mScope.Clone());
- oProv.mScope.Path.NamespacePath = @"ROOT\CCM";
-
- sSiteCode = oProv.ExecuteMethod("SMS_Client", "GetAssignedSite").GetPropertyValue("sSiteCode").ToString();
- return sSiteCode;
- }
- }
-
- set
- {
- if (string.IsNullOrEmpty(value))
- sSiteCode = null;
- else
- {
- WMIProvider oProv = new WMIProvider(oWMIProvider.mScope.Clone());
- oProv.mScope.Path.NamespacePath = @"ROOT\CCM";
-
- ManagementBaseObject inParams = oProv.GetClass("SMS_Client").GetMethodParameters("SetAssignedSite");
- inParams["sSiteCode"] = value;
- oProv.ExecuteMethod("SMS_Client", "SetAssignedSite", inParams);
- //sSiteCode = value;
- sSiteCode = null; //to clear the cached code...
- }
- }
- }
-
- /// <summary>
- /// Get the assigned Management Point
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.ManagementPoint);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.ManagementPoint
- /// </code>
- /// </example>
- public string ManagementPoint
- {
- get
- {
- if (!string.IsNullOrEmpty(sMP))
- return sMP;
- else
- {
- WMIProvider oProv = new WMIProvider(oWMIProvider.mScope.Clone());
- oProv.mScope.Path.NamespacePath = @"ROOT\CCM";
-
- mo_SMS_Authority = oProv.GetObject("SMS_Authority.Name='SMS:" + SiteCode + "'");
- return mo_SMS_Authority.GetPropertyValue("CurrentManagementPoint").ToString();
- }
- }
-
- set
- {
- if (string.IsNullOrEmpty(value))
- sMP = null;
- }
- }
-
- /// <summary>
- /// Get the assigned proxy Management Point (if the client belongs to a secondary site)
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.ProxyManagementPoint);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.ProxyManagementPoint
- /// </code>
- /// </example>
- public string ProxyManagementPoint
- {
- get
- {
- ManagementObjectCollection MPProxies;
- WMIProvider oProv = new WMIProvider(oWMIProvider.mScope.Clone());
- oProv.mScope.Path.NamespacePath = @"ROOT\CCM";
- MPProxies = oProv.ExecuteQuery("SELECT * FROM SMS_MPProxyInformation Where State = 'Active'");
- foreach (ManagementObject MPProxy in MPProxies)
- {
- return MPProxy.GetPropertyValue("Name").ToString();
- }
- return null;
- }
- }
-
- /// <summary>
- /// Get the assigned Internet Management Point
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.InternetMP);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.InternetMP
- /// </code>
- /// </example>
- public string InternetMP
- {
- get
- {
- string sPort = oWMIRegistry.GetString(2147483650, @"SOFTWARE\Microsoft\SMS\Client\Internet Facing", "Internet MP Hostname", "");
- if (string.IsNullOrEmpty(sPort))
- {
- if (this.ComputerSystem.Win32_ComputerSystem["SystemType"].ToString().ToLower().Contains("x64"))
- {
- sPort = oWMIRegistry.GetString(2147483650, @"SOFTWARE\Wow6432Node\Microsoft\SMS\Client\Internet Facing", "Internet MP Hostname", "");
- }
- }
-
- return sPort;
- }
- set
- {
- if (!this.ComputerSystem.Win32_ComputerSystem["SystemType"].ToString().ToLower().Contains("x64"))
- {
- oWMIRegistry.SetStringValue(2147483650, @"SOFTWARE\Microsoft\SMS\Client\Internet Facing", "Internet MP Hostname", value);
- }
- else
- {
- oWMIRegistry.SetStringValue(2147483650, @"SOFTWARE\Wow6432Node\Microsoft\SMS\Client\Internet Facing", "Internet MP Hostname", value);
- }
- }
- }
-
- /// <summary>
- /// Get the assigned DNS Suffix
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.DNSSuffix);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.DNSSuffix
- /// </code>
- /// </example>
- public string DNSSuffix
- {
- get
- {
- string sPort = oWMIRegistry.GetString(2147483650, @"SOFTWARE\Microsoft\CCM\LocationServices", "DnsSuffix", "");
- if (string.IsNullOrEmpty(sPort))
- {
- if (this.ComputerSystem.Win32_ComputerSystem["SystemType"].ToString().ToLower().Contains("x64"))
- {
- sPort = oWMIRegistry.GetString(2147483650, @"SOFTWARE\Wow6432Node\Microsoft\CCM\LocationServices", "DnsSuffix", "");
- }
- }
-
- return sPort;
- }
- set
- {
- if (this.ComputerSystem.Win32_ComputerSystem["SystemType"].ToString().ToLower().Contains("x64"))
- {
- oWMIRegistry.SetStringValue(2147483650, @"SOFTWARE\Wow6432Node\Microsoft\CCM\LocationServices", "DnsSuffix", value);
- }
- else
- {
- oWMIRegistry.SetStringValue(2147483650, @"SOFTWARE\Microsoft\CCM\LocationServices", "DnsSuffix", value);
- }
- }
- }
-
- /// <summary>
- /// Get or Set the HTTP port for Client-Server communication
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.HttpPort);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.HttpPort
- /// </code>
- /// </example>
- public string HttpPort
- {
- get
- {
- string sPort = oWMIRegistry.GetDWord(2147483650, @"SOFTWARE\Microsoft\CCM", "HttpPort", "");
- if (string.IsNullOrEmpty(sPort))
- {
- if (this.ComputerSystem.Win32_ComputerSystem["SystemType"].ToString().ToLower().Contains("x64"))
- {
- sPort = oWMIRegistry.GetDWord(2147483650, @"SOFTWARE\Wow6432Node\Microsoft\CCM", "HttpPort", "");
- }
- }
-
- return sPort;
- }
- set
- {
- if (this.ComputerSystem.Win32_ComputerSystem["SystemType"].ToString().ToLower().Contains("x64"))
- {
- oWMIRegistry.SetDWord(2147483650, @"SOFTWARE\Wow6432Node\Microsoft\CCM", "HttpPort", value);
- }
- else
- {
- oWMIRegistry.SetDWord(2147483650, @"SOFTWARE\Microsoft\CCM", "HttpPort", value);
- }
- }
- }
-
- /// <summary>
- /// Get or Set the SCCM Server Locator Point
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.ServerLocatorPoint);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.ServerLocatorPoint
- /// </code>
- /// </example>
- public string ServerLocatorPoint
- {
- get
- {
- if (!this.oWMIProvider.isX86)
- {
- return oWMIRegistry.GetString(2147483650, @"SOFTWARE\Wow6432Node\Microsoft\CCM", "SMSSLP");
- }
- else
- {
- return oWMIRegistry.GetString(2147483650, @"SOFTWARE\Microsoft\CCM", "SMSSLP");
- }
- }
- set
- {
- if (!this.oWMIProvider.isX86)
- {
- oWMIRegistry.SetStringValue(2147483650, @"SOFTWARE\Wow6432Node\Microsoft\CCM", "SMSSLP", value);
- }
- else
- {
- oWMIRegistry.SetStringValue(2147483650, @"SOFTWARE\Microsoft\CCM", "SMSSLP", value);
- }
- }
- }
-
- /// <summary>
- /// Get or Set the SMS Cache Path
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.CachePath);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.CachePath
- /// </code>
- /// </example>
- public string CachePath
- {
- get
- {
- return mCacheConfig.GetPropertyValue("Location").ToString();
- }
-
- set
- {
- string CachePath = value;
- if (CachePath.Length > 3)
- {
- ManagementObject MO = mCacheConfig;
- MO.SetPropertyValue("Location", CachePath);
- MO.Put();
- mCacheConfig = MO;
- }
-
- }
- }
-
- /// <summary>
- /// Get or Set the SMS Cache Size in Megabyte (MB)
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// UInt32 CacheSize = UInt32.Parse(oClient.CacheSize);
- /// if (CacheSize != 600)
- /// {
- /// //Set the CacheSize to 600MB
- /// oClient.CacheSize = "600";
- /// }
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.CacheSize = "600"
- /// </code>
- /// </example>
- public string CacheSize
- {
- get
- {
- return mCacheConfig.GetPropertyValue("Size").ToString();
- }
-
- set
- {
- UInt32 CacheSize = System.Convert.ToUInt32(value);
-
- if (CacheSize > 0)
- {
- ManagementObject MO = mCacheConfig;
- MO.SetPropertyValue("Size", CacheSize);
- MO.Put();
- mCacheConfig = MO;
- }
-
- }
- }
-
- /// <summary>
- /// Size of the downloaded packages in cache
- /// </summary>
- public Int32 CacheContentSize
- {
- get
- {
- ManagementObjectCollection MOC;
- WMIProvider oProv = new WMIProvider(oWMIProvider.mScope.Clone());
- oProv.mScope.Path.NamespacePath = @"root\ccm\SoftMgmtAgent";
-
- if (this.SMSVersion.StartsWith("4"))
- {
- MOC = oProv.ExecuteQuery("SELECT * FROM CacheInfoEx");
- }
- else
- {
-
- MOC = oProv.ExecuteQuery("SELECT * FROM CacheInfo");
- }
- Int32 uSize = 0;
-
- foreach (ManagementObject MO in MOC)
- {
- uSize = uSize + Int32.Parse(MO.GetPropertyValue("ContentSize").ToString());
- }
- return uSize;
-
- }
- }
-
- /// <summary>
- /// Allow the local Admin to override Site Settings
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// //Prevent an Admin to change SMS Settings (Control Panel)
- /// oClient.AllowLocalAdminOverride = false;
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.AllowLocalAdminOverride = "False"
- /// </code>
- /// </example>
- public bool AllowLocalAdminOverride
- {
- get
- {
- return Boolean.Parse(mSMS_Client.GetPropertyValue("AllowLocalAdminOverride").ToString());
- }
- set
- {
- ManagementObject MO = mSMS_Client;
- MO.SetPropertyValue("AllowLocalAdminOverride", value);
- MO.Put();
- mSMS_Client = MO;
- MO.Dispose();
- }
- }
-
- /// <summary>
- /// Get the SMS Agent Type
- /// </summary>
- /// <remarks>
- /// <list type="bullet">
- /// <item>1 = Advanced Client</item>
- /// <item>0 = Legacy Client</item>
- /// </list>
- /// </remarks>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// if (oClient.ClientType == 1)
- /// {
- /// Console.WriteLine("Advanced Client");
- /// }
- /// else
- /// {
- /// Console.WriteLine("Legacy Client");
- /// }
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.ClientType
- /// </code>
- /// </example>
- public int ClientType
- {
- get
- {
- return int.Parse(mSMS_Client.GetPropertyValue("ClientType").ToString());
- }
- }
-
- /// <summary>
- /// Enable automatic Site assignment.
- /// <para>This will force the SMS Client to automatically reassign the SMS Site if the client roams to another SMS Primary Site.</para>
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// oClient.EnableAutoAssignment = true;
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.EnableAutoAssignment = "True"
- /// </code>
- /// </example>
- public bool EnableAutoAssignment {
- get
- {
- return bool.Parse(mSMS_Client.GetPropertyValue("EnableAutoAssignment").ToString());
- }
- set
- {
- //WMIProvider oProv = new WMIProvider(oWMIProvider.mScope);
- //oProv.mScope.Path.NamespacePath = @"ROOT\CCM";
- ManagementObject MO = mSMS_Client;
- MO.SetPropertyValue("EnableAutoAssignment", value);
- MO.Put();
-
- //Refresh cached Object
- mSMS_Client = MO;
-
- MO.Dispose();
- }
- }
-
- /// <summary>
- /// Get the SMS GUID
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.ClientId);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.ClientID
- /// </code>
- /// Output Example:
- /// <code>
- /// GUID:645567CB-D0C5-4A31-8D54-A74A88E565C4
- /// </code>
- /// </example>
- public string ClientId
- {
- get
- {
- return mCCM_Client.GetPropertyValue("ClientId").ToString();
- }
- }
-
- /// <summary>
- /// Delete the SMS/SCCM GUID on next SMS Agent restart
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// oClient.DeleteGUID();
- /// oClient.RestartSMSAgent();
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.DeleteGUID()
- /// $SMSClient.RestartSMSAgent()
- /// </code>
- /// </example>
- public void DeleteGUID()
- {
- if (this.SMSVersion.StartsWith("4"))
- {
- //Create an SMSCFG.INI File with a new, random GUID ...
- using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"\\" + this.Connection.mScope.Path.Server + @"\admin$\SMSCFG.INI", false))
- {
- sw.WriteLine("[Configuration - Client Properties]");
- sw.WriteLine("SMS Unique Identifier=GUID:" + System.Guid.NewGuid().ToString().ToUpper());
- sw.Close();
- }
- }
- else
- {
- //On SMS2003 Agents, delete the smscfg.ini
- string WinDir = ComputerSystem.WindowsDirectory;
- FileIO.DeleteFile(WinDir + @"\smscfg.ini");
- }
- }
-
- /// <summary>
- /// Get the last GUID change date
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.ClientIdChangeDate);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.ClientIDChangeDate
- /// </code>
- /// Output Example:
- /// <code>
- /// 12/22/2006 15:18:10
- /// </code>
- /// </example>
- public string ClientIdChangeDate
- {
- get
- {
- return mCCM_Client.GetPropertyValue("ClientIdChangeDate").ToString();
- }
- }
-
- /// <summary>
- /// Get the previous SMS GUID
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.PreviousClientID);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.PreviousClientID
- /// </code>
- /// Output Example:
- /// <code>
- /// GUID:645567CB-D0C5-4A31-8D54-A74A88E565C4
- /// </code>
- /// </example>
- public string PreviousClientId
- {
- get
- {
- return mCCM_Client.GetPropertyValue("PreviousClientId").ToString();
- }
- }
-
- /// <summary>
- /// Get the SMS Version (like 2.50 )
- /// </summary>
- /// <value>
- /// Known SMS Versions:
- /// <list type="bullet">
- /// <item>2.50 = SMS 2003</item>
- /// <item>2.00 = SMS 2.0</item>
- /// </list>
- /// </value>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.SMSVersion);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.SMSVersion
- /// </code>
- /// </example>
- public string SMSVersion
- {
- get
- {
- if (string.IsNullOrEmpty(sSMSVersion))
- {
- string sVersion = mSMS_Client.GetPropertyValue("ClientVersion").ToString();
- return sVersion;
- }
- else
- return sSMSVersion;
- }
- set
- {
- sSMSVersion = "";
- oSMS_Client = null;
- }
- }
-
- /// <summary>
- /// Get the Log-Directory Path
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.LogDirectory);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.LogDirectory
- /// </code>
- /// Output Example:
- /// <code>
- /// C:\WINDOWS\system32\CCM\Logs
- /// </code>
- /// </example>
- public string LogDirectory
- {
- get
- {
- WMIProvider oProv = new WMIProvider(oWMIProvider.mScope.Clone());
- oProv.mScope.Path.NamespacePath = @"ROOT\CCM\Policy\Machine";
- return oProv.GetObject("CCM_Logging_GlobalConfiguration.DummyKey=1").GetPropertyValue("LogDirectory").ToString();
- }
- }
-
- /// <summary>
- /// Get the Local SMS Path
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.LocalSMSPath);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.LocalSMSPath
- /// </code>
- /// Output Example:
- /// <code>
- /// C:\WINDOWS\system32\CCM
- /// </code>
- /// </example>
- public string LocalSMSPath
- {
- get
- {
- if (string.IsNullOrEmpty(sLocalSMSPath))
- {
- sLocalSMSPath = oWMIRegistry.GetString(2147483650, @"SOFTWARE\Microsoft\SMS\Client\Configuration\Client Properties", "Local SMS Path");
- }
- return sLocalSMSPath;
- }
- }
-
- /// <summary>
- /// Get the MSI ProductCode of the installed SMS Client Agent
- /// </summary>
- /// <example>
- /// C#:
- /// <code>
- /// using System;
- /// using System.Collections.Generic;
- /// using System.Text;
- /// using smsclictr.automation;
- /// using System.Management;
- ///
- /// namespace ConsoleApplication1
- /// {
- /// class Program
- /// {
- /// static void Main(string[] args)
- /// {
- /// SMSClient oClient = new SMSClient("workstation01");
- /// Console.WriteLine(oClient.ProductCode);
- /// }
- /// }
- /// }
- /// </code>
- /// PowerShell:
- /// <para>(copy smsclictr.automation.dll to the %HOMEDRIVE%\%HOMEPATH% Folder of the current User)</para>
- /// <code>
- /// [void][System.Reflection.Assembly]::LoadFile("$HOME\smsclictr.automation.dll")
- /// $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("workstation01")
- /// $SMSClient.ProductCode
- /// </code>
- /// Output Example:
- /// <code>
- /// {D97113AD-690F-4169-8637-4A046282D8F6}
- /// </code>
- /// </example>
- public string ProductCode
- {
- get…