how to know if an application is installed lazarus / 21-General ---------------------------------------------------------------------- Ericktux · 2022-09-01 16:37 hello friends good morning, how can I know if an application is installed, and if it is installed know its version and exact location. i am using lazarus on windows 10x64 ---------------------------------------------------------------------- af0815 · 2022-09-01 17:06 This not a Lazarus question, it is a windows question. How should the system know about a program ? Maybe with wmi you can query this or on the powershell. https://social.microsoft.com/Forums/en-US/225fe388-a26f-4457-8eba- ebf122006da2/find-software-with-version-using-powershell- command?forum=Offtopic ---------------------------------------------------------------------- Mr.Madguy · 2022-09-01 17:18 [HKCU or HKLM]\Software\[Wow6432Node\]Microsoft\Windows\CurrentVersion \Uninstall Search for your application there. Version is "DisplayVersion". Not all applications provide it. Location is "InstallLocation". ---------------------------------------------------------------------- balazsszekely · 2022-09-01 19:53 You can try something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.GetInstalledPrograms(ALW: TListView; ARootKey: HKEY;  AInstallType: TInstallType; AIgnoreMSEntries: Boolean);const  KeyName = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\' ;var  Reg: TRegistry;  KeyAccess: LongWord;  SL: TStringList;  I: Integer;  InstName, InstPublisher, InstPath: String;  VerMaj, VerMin: Integer;  InstVer: String;begin  KeyAccess := KEY_READ;  if AInstallType = it64bit then    KeyAccess := KeyAccess + KEY_WOW64_64KEY;  Reg := TRegistry.Create(KeyAccess);  try    Reg.RootKey := ARootKey;    if Reg.OpenKey(KeyName, False) = True then    begin      SL := TStringList.Create;      try        Reg.GetKeyNames(SL);        Reg.CloseKey;        for I := 0 to SL.Count - 1 do        begin        if Reg.OpenKey(KeyName + SL[I], False) then          begin          if Reg.ValueExists('DisplayName') and (Reg.GetDataType('DisplayName') = rdString) then              InstName := Reg.ReadString('DisplayName');            if (Trim(InstName) = '') or (IsInList(InstName, ALW)) then            begin              Reg.CloseKey;              Continue;            end;             if Reg.ValueExists('Publisher') and (Reg.GetDataType('Publisher') = rdString) then              InstPublisher := Reg.ReadString('Publisher');            if (AIgnoreMSEntries) and (Trim(InstPublisher) <> '') and (Pos('Microsoft', InstPublisher) > 0) then            begin              Reg.CloseKey;              Continue;            end;             VerMaj := 0; VerMin := 0;          if Reg.ValueExists('VersionMajor') and (Reg.GetDataType('VersionMajor') = rdInteger) then              VerMaj := Reg.ReadInteger('VersionMajor');            if Reg.ValueExists('VersionMinor') and (Reg.GetDataType('VersionMajor') = rdInteger) then              VerMin := Reg.ReadInteger('VersionMinor');            InstVer := IntToStr(VerMaj) + '.' + IntToStr(VerMin);            if InstVer = '0.0' then InstVer := '-';             InstPath := Reg.ReadString('InstallLocation');             with ALW.Items.Add do          begin              Caption := InstName;              SubItems.Add(InstPublisher);              SubItems.Add(InstVer);            SubItems.Add(InstPath);            end;            Reg.CloseKey;          end;        end;      finally        SL.Free;    end;    end;  finally    Reg.Free;  endend; Microsoft entries are ignored by default, you can change that in the function call. To find a particular item, just loop through the ListWiew(this is not implemented). ---------------------------------------------------------------------- Zvoni · 2022-09-02 07:05 Since a program is always installed on a machine, the only plausible Root-Key in the Registry is HKLM Instead of looking for the Uninstall (which implies the program offers an uninstall-routine), i'd rather search for it in \HKEY_LOCAL_MACHINE\SOFTWARE if it appears there. To make sure it's not a "dead corpse" in the registry you could even look for sub-entries like "PathToExe", or "InstallDir" And don't forget the SysWOW64-Node ---------------------------------------------------------------------- balazsszekely · 2022-09-02 07:39 @Zvoni QuoteSince a program is always installed on a machine, the only plausible Root-Key in the Registry is HKLMThat's not true. You can install an application only for a particular user(HKEY_CURRENT_USER) or for everyone(HKEY_LOCAL_MACHINE). QuoteInstead of looking for the Uninstall (which implies the program offers an uninstall-routine)."Add remove programs" from control panel does the same. As a quick test, I deleted the following key: "\HKEY_LO CAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\7- Zip". As a result, 7-Zip has also disappeared from the "Add remove programs" list. As a side note, I did exported the key first. Quotei'd rather search for it in \HKEY_LOCAL_MACHINE\SOFTWARE if it appears there.\HKEY_LOCAL_MACHINE\SOFTWARE does not contain any information about the application name, version or publisher. See OP's original request. ---------------------------------------------------------------------- Zvoni · 2022-09-02 10:12 Quote from: GetMem on September 02, 2022, 09:39:04 am@Zvoni QuoteSince a program is always installed on a machine, the only plausible Root-Key in the Registry is HKLMThat's not true. You can install an application only for a particular user(HKEY_CURRENT_USER) or for everyone(HKEY_LOCAL_MACHINE). The first time i hear that. What utter nonsense. Which imbecile decided that to be a smart idea? QuoteQuoteInstead of looking for the Uninstall (which implies the program offers an uninstall-routine)."Add remove programs" from control panel does the same. As a quick test, I deleted the following key: "\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Un install\7-Zip". As a result, 7-Zip has also disappeared from the "Add remove programs" list. As a side note, I did exported the key first. Quotei'd rather search for it in \HKEY_LOCAL_MACHINE\SOFTWARE if it appears there.\HKEY_LOCAL_MACHINE\SOFTWARE does not contain any information about the application name, version or publisher. See OP's original request. OK, agreed, i wasn't precise enough. Starting at the mentioned Key, if i know the Publisher, go there, if i know the Program-name, go there etc. if i don't know the publisher, i would just traverse all keys/subkeys (recursively?) in the registry from that starting point Depends how often i would have to call that function Ah yes, how i miss the "which"-command on windows.... (and yes, i know: if a custom path of the Program is not in PATH-Variable, then there is nothing to find) ---------------------------------------------------------------------- balazsszekely · 2022-09-02 11:02 @Zvoni QuoteThe first time i hear that. What utter nonsense. Which imbecile decided that to be a smart idea?Well it makes sense for multi-user environment. For example, if you install Lazarus only on your account, your wife and the kids desktop won't be "infested" with a Lazarus icon. More over, if the permissions are configured correctly, they won't be able to delete your personal files and vice versa. I know nowadays almost everyone has a its own device, so the above issue is irrelevant. It was a valid paradigm back in the '90 though, still valid for institutions. On the other hand, I full heartedly agree that the whole install/unistall mechanism is fundamentally flawed on windows. This is the reason why, in relatively short time, the registry will be full with trash(invalid keys, values pointing to non existing paths, etc). ---------------------------------------------------------------------- Kays · 2022-09-02 12:08 Quote from: Ericktux on September 01, 2022, 06:37:04 pm[…] how can I know if an application is installed, and if it is installed know its version and exact location. […]This smells like TOCTOU: Your program has to presume all its dependencies are properly installed because you never know whether a deinstallation is in progress and thus the application may be gone the next second. Do or die is the maxim. Quote from: GetMem on September 02, 2022, 09:39:04 am\HKEY_LOCAL_MACHINE\SOFTWARE does not contain any information about the application name, version or publisher.Well, if you got the InstallLocation: Some vendors add version/name/publisher information to the executable file. ---------------------------------------------------------------------- Ericktux · 2022-09-03 16:35 Quote from: GetMem on September 01, 2022, 09:53:29 pmYou can try something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.GetInstalledPrograms(ALW: TListView; ARootKey: HKEY;  AInstallType: TInstallType; AIgnoreMSEntries: Boolean);const  KeyName = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\' ;var  Reg: TRegistry;  KeyAccess: LongWord;  SL: TStringList;  I: Integer;  InstName, InstPublisher, InstPath: String;  VerMaj, VerMin: Integer;  InstVer: String;begin  KeyAccess := KEY_READ;  if AInstallType = it64bit then    KeyAccess := KeyAccess + KEY_WOW64_64KEY;  Reg := TRegistry.Create(KeyAccess);  try    Reg.RootKey := ARootKey;    if Reg.OpenKey(KeyName, False) = True then    begin      SL := TStringList.Create;      try        Reg.GetKeyNames(SL);        Reg.CloseKey;        for I := 0 to SL.Count - 1 do        begin        if Reg.OpenKey(KeyName + SL[I], False) then          begin          if Reg.ValueExists('DisplayName') and (Reg.GetDataType('DisplayName') = rdString) then              InstName := Reg.ReadString('DisplayName');            if (Trim(InstName) = '') or (IsInList(InstName, ALW)) then            begin              Reg.CloseKey;              Continue;            end;             if Reg.ValueExists('Publisher') and (Reg.GetDataType('Publisher') = rdString) then              InstPublisher := Reg.ReadString('Publisher');            if (AIgnoreMSEntries) and (Trim(InstPublisher) <> '') and (Pos('Microsoft', InstPublisher) > 0) then            begin              Reg.CloseKey;              Continue;            end;             VerMaj := 0; VerMin := 0;          if Reg.ValueExists('VersionMajor') and (Reg.GetDataType('VersionMajor') = rdInteger) then              VerMaj := Reg.ReadInteger('VersionMajor');            if Reg.ValueExists('VersionMinor') and (Reg.GetDataType('VersionMajor') = rdInteger) then              VerMin := Reg.ReadInteger('VersionMinor');            InstVer := IntToStr(VerMaj) + '.' + IntToStr(VerMin);            if InstVer = '0.0' then InstVer := '-';             InstPath := Reg.ReadString('InstallLocation');             with ALW.Items.Add do          begin              Caption := InstName;              SubItems.Add(InstPublisher);              SubItems.Add(InstVer);            SubItems.Add(InstPath);            end;            Reg.CloseKey;          end;        end;      finally        SL.Free;    end;    end;  finally    Reg.Free;  endend; Microsoft entries are ignored by default, you can change that in the function call. To find a particular item, just loop through the ListWiew(this is not implemented). thank you very much friend, your code works perfect, a query how I can perform a search and obtain all the data of the found row ?? ---------------------------------------------------------------------- Ericktux · 2022-09-04 07:17 hello friends I can now search and obtain data, I also modified the original example to be able to detect more programs, I share them. many thanks to Getmem for his time and help.