简体   繁体   中英

How to determine whether a specific application is installed on my domain computers

How to determine whether a specific application is installed on my domain computers using C#?

Forgot to mention. I have admin rights on the domain

I cannot respond to peoples' questions... so I keep editing my post. .. The application is registered under Add/Remove in Control Panel

Since your application is actually stored within your Control Panel, that means that it is generating a Registry Key. Since it generates a key for the msiexec utility. Your application information will be here:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

What this means, is your Registry will contain information in the following categories:

  • Display Name
  • UninstallString
  • Publisher

It includes a lot more, except those three will be the most viable.

  • Display Name: Should contain your products name.
  • UninstallString: This will contain your product GUID
  • Publisher: Is the company name.

So you can actually implement some basic Remoting, have a server force a user to run a .bat that will run your application, and etc.

But one of the key values, is you can just do a simple loop within your Registry to determine if it is installed.

Here is a tutorial .

In order to iterate through you need to do something such as:

// Registry 'MSIEXEC Guid'
public void RegistryFix()
{            
    // Create a Registry Instance.
    RegistryKey rKey = Registry.LocalMachine.OpenSubKey(@"\\SOFTWARE\\Microsoft
        \\Windows\\CurrentVersion\\Uninstall", true);

    // Loop Our Instance:
    foreach( string sub in rKey.GetSubKeyNames() )
    {

         #region Error Handling for 'Registry MSIEXEC'

         try
         {
             // Locate Boulevard Instance
             RegistryKey blvd = rKey.OpenSubKey(@"\\SOFTWARE\\Microsoft
                 \\Windows\\CurrentVersion\\Uninstall\\" + sub);

              // Specify Boulevard Display Name String
              string blvdDisplay = blvd.GetValue("DisplayName").ToString();

              // Search For:
              if (blvdDisplay.Contains("Boulevard"))
              {

                    // Now Obtain Uninstall String.
                    string blvdUninstall =   blvd.GetValue("UninstallString").ToString().Replace(@"/u", @"/f");

                     // Execute
                     Process u = Process.Start(blvdUninstall);
                     u.WaitForExit();

               }
           }
           #endregion

         // Unhandled / Null Error
         catch
        {                    
               // Write Exception:
               Console.WriteLine("Null Value Detected");
               throw new Exception("Invalid or Null Registry Value Detected.");
        } 
   }                         
}

So the above example is running a recursive loop and searching those Subkeys for the msiexec so it can initiate a repair. So I didn't post all of the code for it to actually do that, but the point was to show you how to search those Registry Keys so you can choose what best fits your needs.

Now this is designed to run locally, so you may have to create an executable then create a logon.bat so once a user logs in it checks if it is installed and runs your application.

You can use Remoting, there are a lot of variations in order to run an application remotely. You'll have to find what best suits you. Hopefully this helps you.

To explain a little bit about the above code fragment, in my implementation a local machine would start the application. It runs through a diagnoses phase to attempt to fix common errors encountered. The easiest way to calculate a large array of applications was to have ours linked to database which stores all the product Guids.

So your request is very, very possible. This should solve the question and point you where you need to go to actually implement it as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM