GPG detection on Windows?

Jerry jerry at seibercom.net
Thu Jul 18 21:25:01 CEST 2013


On Thu, 18 Jul 2013 12:15:51 -0500
Anthony Papillion articulated:

> I'm designing an application that will run on Windows and utilize
> GNUPG. Right now, I'm detecting if GPG is installed by calling it then
> parsing the output of the command to see if it succeeded or failed.
> This is VERY messy and not my preferred way.
> 
> Does GPG4Win install anything to the registry that I could check for
> to see if it's installed?

The software details installed in a PC is found in the registry in the
location HEKY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall .
You can use the following code to get the list of software programs
installed in the system. You can determine whether it is latest using
the InstallDate key in the registry.

 

	/// <summary>
  /// Gets a list of installed software and, if known, the software's install path.
  /// </summary>
  /// <returns></returns>
  private string Getinstalledsoftware()
  {
   //Declare the string to hold the list:
   string Software = null;

   //The registry key:
   string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
   using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
   {
    //Let's go through the registry keys and get the info we need:
    foreach (string skName in rk.GetSubKeyNames())
    {
     using (RegistryKey sk = rk.OpenSubKey(skName))
     {
      try
      {
       //If the key has value, continue, if not, skip it:
       if (!(sk.GetValue("DisplayName") == null))
       {
        //Is the install location known?
        if (sk.GetValue("InstallLocation") == null)
         Software += sk.GetValue("DisplayName") + " - Install path not known\n"; //Nope, not here.
        else
         Software += sk.GetValue("DisplayName") + " - " + sk.GetValue("InstallLocation") + "\n"; //Yes, here it is...
       }
      }
      catch (Exception ex)
      {
       //No, that exception is not getting away... :P
      }
     }
    }
   }

   return Software;
  }


//EXAMPLE USAGE:
private void get_software_list_button__Click(object sender, EventArgs e)
  {
   MessageBox.Show(Getinstalledsoftware());
  }

-- 
Jerry ♔

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the Reply-To header.
__________________________________________________________________




More information about the Gnupg-users mailing list