public static bool IpIsDeployed(string productCode, string computerName) { // check this key: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\SystemCenter2012\Orchestrator\IPs // and enumerate the subkeys to find the one matching the programcode (this key is set when msi is installed) RegistryKey key; if ((string.IsNullOrEmpty(computerName) || (Utilities.IsLocalComputer(computerName)))) { key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); } else { key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, computerName, RegistryView.Registry64); } RegistryKey ipKey = key.OpenSubKey(_ipsRegistryKey); String[] ValueNames = ipKey.GetValueNames(); foreach (string name in ValueNames) { string value = ipKey.GetValue(name).ToString(); if (string.Compare(value, GuidUtilities.AddBracesToGuid(productCode), true) == 0) { return(true); } } return(false); }
public static string GetDeployedIpVersion(string productCode, string computerName) { string version = string.Empty; string uninstallKey = GuidUtilities.AddBracesToGuid(productCode); RegistryKey key; if ((string.IsNullOrEmpty(computerName) || (Utilities.IsLocalComputer(computerName)))) { key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); } else { key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, computerName, RegistryView.Registry64); } string baseKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"; RegistryKey ipKey = key.OpenSubKey(baseKey + uninstallKey); if (null == ipKey) { return(string.Empty); } object versionObj = ipKey.GetValue("DisplayVersion"); if (null != versionObj) { return(versionObj.ToString()); } return(string.Empty); }
public static string GetOIPFilePath(string packID, string managementServerName) { string oipFile = Path.Combine(_scoCommonFilesFolder, _packsPath, GuidUtilities.AddBracesToGuid(packID) + ".oip"); if ((string.IsNullOrEmpty(managementServerName) || (Utilities.IsLocalComputer(managementServerName)))) { if (File.Exists(oipFile)) { return(oipFile); } } else { if (File.Exists(oipFile)) { return(oipFile); } } return(null); }
public static string UninstallMsi(string productCode, string computerName, ConnectionOptions connectionOptions) { //uses WMI to uninstall the application, then deletes the MSI from the Management Server path StringBuilder log = new StringBuilder(); string selectQuery = string.Format("Select * FROM Win32_Product Where IdentifyingNumber = '{0}'", GuidUtilities.AddBracesToGuid(productCode)); //ConnectionOptions oConn = new ConnectionOptions(); //oConn.Username = "******"; //oConn.Password = "******"; ManagementObjectCollection products = WMIUtilities.QueryWMI(selectQuery, computerName, connectionOptions); log.AppendLine(string.Format("Found [{0}] matches", products.Count)); foreach (ManagementObject product in products) { log.Append(string.Format("Uninstalling '{0}'", product.Properties["Name"].ToString())); var result = product.InvokeMethod("Uninstall", null); log.Append(string.Format("The Uninstall method result is {0}", result.ToString())); } return(log.ToString()); }