Uninstall a none Microsoft program on a remote machine via WMI
-
Dear All, I am scratching my head about 4 hours to get this sorted, but without any luck. what i would like to do is on my windows form, it connects to a remote machine and then display all the programs that installed on a windows server 2003 box on a ListBox, then user can select one of the program, and click the Uninstall button to uninstall the selected program. I am able to load all the programs installed on the remote machines by this code:
public static ArrayList GetAppLists(string p_machineName)
{
RegistryHive hive = RegistryHive.LocalMachine;
RegistryKey subKey;
string displayName, displayVersion, keyNameCurrentMachine32;
ArrayList al = new ArrayList();
//ArrayList uninstallStrings = new ArrayList();keyNameCurrentMachine32 = @"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; using (RegistryKey regHive = RegistryKey.OpenRemoteBaseKey(hive, p\_machineName)) { using (RegistryKey regKey = regHive.OpenSubKey(keyNameCurrentMachine32)) { if (regKey != null) { foreach (string k in regKey.GetSubKeyNames()) { using (subKey = regKey.OpenSubKey(k)) { displayName = subKey.GetValue("DisplayName") as string; displayVersion = subKey.GetValue("DisplayVersion") as string; if (!string.IsNullOrEmpty(displayName)) { al.Add(displayName + " " + displayVersion); } } } } } } return al; }
but when i try to uninstall the particular progarm by this code:
private void UninstallProgram()
{
ConnectionOptions connection = new ConnectionOptions();
connection.Username = txtDomain.Text + "\\" + txtUserName.Text;
connection.Password = txtPassword.Text;
connection.Impersonation = ImpersonationLevel.Impersonate;
connection.Authentication = AuthenticationLevel.Packet;
connection.EnablePrivileges = true;ManagementScope scope = new ManagementScope(@"\\\\" + cbServerAddress
-
Dear All, I am scratching my head about 4 hours to get this sorted, but without any luck. what i would like to do is on my windows form, it connects to a remote machine and then display all the programs that installed on a windows server 2003 box on a ListBox, then user can select one of the program, and click the Uninstall button to uninstall the selected program. I am able to load all the programs installed on the remote machines by this code:
public static ArrayList GetAppLists(string p_machineName)
{
RegistryHive hive = RegistryHive.LocalMachine;
RegistryKey subKey;
string displayName, displayVersion, keyNameCurrentMachine32;
ArrayList al = new ArrayList();
//ArrayList uninstallStrings = new ArrayList();keyNameCurrentMachine32 = @"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; using (RegistryKey regHive = RegistryKey.OpenRemoteBaseKey(hive, p\_machineName)) { using (RegistryKey regKey = regHive.OpenSubKey(keyNameCurrentMachine32)) { if (regKey != null) { foreach (string k in regKey.GetSubKeyNames()) { using (subKey = regKey.OpenSubKey(k)) { displayName = subKey.GetValue("DisplayName") as string; displayVersion = subKey.GetValue("DisplayVersion") as string; if (!string.IsNullOrEmpty(displayName)) { al.Add(displayName + " " + displayVersion); } } } } } } return al; }
but when i try to uninstall the particular progarm by this code:
private void UninstallProgram()
{
ConnectionOptions connection = new ConnectionOptions();
connection.Username = txtDomain.Text + "\\" + txtUserName.Text;
connection.Password = txtPassword.Text;
connection.Impersonation = ImpersonationLevel.Impersonate;
connection.Authentication = AuthenticationLevel.Packet;
connection.EnablePrivileges = true;ManagementScope scope = new ManagementScope(@"\\\\" + cbServerAddress