marksmall
asked on
getting list of installed programs
how can i get a list of installed programs intoa listbox and then have the ability to delete/unistall them through my delphi application!
is that possible?
is that possible?
Hi,
try this function:
// If the function succeeds, the return value is the number of installed programs
// otherwise the return value is -1
Function GetInstalledPrograms(PRGLi stBox : TListBox) : Integer;
VAR
rs : string;
OpenKey : HKEY;
KeyIndex,
KeyNameLength,
RetValue : Cardinal;
KeyNameBuf : array of char;
Function GetDisplayName(KeyName : String) : string;
VAR
PRGKey : HKEY;
NameBuf : array[0..255] of char;
ValueType,
ValueSize : Cardinal;
err : Cardinal;
Begin
Result := '';
IF REGOpenKey(HKEY_LOCAL_MACH INE,
PCHAR('SOFTWARE\Microsoft\ Windows\Cu rrentVersi on\Uninsta ll'+'\' + KeyName),
PRGKey)
<> ERROR_SUCCESS then Result := '*' else
Begin
ValueSize := Length(NameBuf);
IF REGQueryValueEx(PRGKey, PCHAR('Displayname'), NIL, @ValueType, @NameBuf, @ValueSize)
<> ERROR_SUCCESS then
Begin
ValueSize := Length(NameBuf);
IF REGQueryValueEx(PRGKey, PCHAR('QuietDisplayname'), NIL, @ValueType, @NameBuf, @ValueSize)
<> ERROR_SUCCESS then Result := KeyName;
End;
IF Result = '' then Result := STRING(NameBuf);
REGCloseKey(PRGKey);
End;
End;
Begin
Result := 0;
SetLength(KeyNameBuf, 256);
// Open Key
IF REGOpenKey(HKEY_LOCAL_MACH INE,
PCHAR('SOFTWARE\Microsoft\ Windows\Cu rrentVersi on\Uninsta ll'),
OpenKey)
<> ERROR_SUCCESS then Result := -1 else
Begin
KeyIndex := 0;
Repeat
KeyNameLength := Length(KeyNameBuf);
RetValue := RegEnumKeyEx(OpenKey, KeyIndex, PCHAR(KeyNameBuf),
KeyNameLength, NIL, NIL, NIL, NIL);
IF RetValue = ERROR_SUCCESS then
Begin
rs := GetDisplayName(PCHAR(KeyNa meBuf));
IF rs <> '*' then
Begin
//add the PRG Name to the listbox
PRGListBox.Items.Add(rs);
Inc(Result);
End else Result := -1;
End;
Inc(KeyIndex);
Application.ProcessMessage s;
Until (RetValue <> ERROR_SUCCESS)or(Result = -1);
RegCloseKey(OpenKey);
End;
SetLength(KeyNameBuf, 0);
End;
ex. call:
procedure TForm1.Button1Click(Sender : TObject);
begin
IF GetInstalledPrograms(ListB ox1) = -1 then ShowMessage('ERROR');
end;
GL
Bug
try this function:
// If the function succeeds, the return value is the number of installed programs
// otherwise the return value is -1
Function GetInstalledPrograms(PRGLi
VAR
rs : string;
OpenKey : HKEY;
KeyIndex,
KeyNameLength,
RetValue : Cardinal;
KeyNameBuf : array of char;
Function GetDisplayName(KeyName : String) : string;
VAR
PRGKey : HKEY;
NameBuf : array[0..255] of char;
ValueType,
ValueSize : Cardinal;
err : Cardinal;
Begin
Result := '';
IF REGOpenKey(HKEY_LOCAL_MACH
PCHAR('SOFTWARE\Microsoft\
PRGKey)
<> ERROR_SUCCESS then Result := '*' else
Begin
ValueSize := Length(NameBuf);
IF REGQueryValueEx(PRGKey, PCHAR('Displayname'), NIL, @ValueType, @NameBuf, @ValueSize)
<> ERROR_SUCCESS then
Begin
ValueSize := Length(NameBuf);
IF REGQueryValueEx(PRGKey, PCHAR('QuietDisplayname'),
<> ERROR_SUCCESS then Result := KeyName;
End;
IF Result = '' then Result := STRING(NameBuf);
REGCloseKey(PRGKey);
End;
End;
Begin
Result := 0;
SetLength(KeyNameBuf, 256);
// Open Key
IF REGOpenKey(HKEY_LOCAL_MACH
PCHAR('SOFTWARE\Microsoft\
OpenKey)
<> ERROR_SUCCESS then Result := -1 else
Begin
KeyIndex := 0;
Repeat
KeyNameLength := Length(KeyNameBuf);
RetValue := RegEnumKeyEx(OpenKey, KeyIndex, PCHAR(KeyNameBuf),
KeyNameLength, NIL, NIL, NIL, NIL);
IF RetValue = ERROR_SUCCESS then
Begin
rs := GetDisplayName(PCHAR(KeyNa
IF rs <> '*' then
Begin
//add the PRG Name to the listbox
PRGListBox.Items.Add(rs);
Inc(Result);
End else Result := -1;
End;
Inc(KeyIndex);
Application.ProcessMessage
Until (RetValue <> ERROR_SUCCESS)or(Result = -1);
RegCloseKey(OpenKey);
End;
SetLength(KeyNameBuf, 0);
End;
ex. call:
procedure TForm1.Button1Click(Sender
begin
IF GetInstalledPrograms(ListB
end;
GL
Bug
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
HKEY_LOCAL_MACHINE\SOFTWAR
Loop through all the keys in there, and the description for each key is in a StringValue called DisplayName
To remove it, just delete the subkey.
To uninstall it, read the StringValue called UninstallString, and just execute the command.
NOTE: Those without a DisplayName should be ignored.
DragonSlayer.