Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Uninstall a none Microsoft program on a remote machine via WMI

Uninstall a none Microsoft program on a remote machine via WMI

Scheduled Pinned Locked Moved C#
sysadminwindows-adminsecurity
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndieDu
    wrote on last edited by
    #1

    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
    
    A 1 Reply Last reply
    0
    • A AndieDu

      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
      
      A Offline
      A Offline
      AndieDu
      wrote on last edited by
      #2

      no one had any clue or i just posted in the wrong section of this forum?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups