Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Check whether a user has a shortcut installed
This article has not been rated yet. After reading, feel free to leave comments and rate it.
The following routine checks whether a shortcut or a file with a given
name is either on the desktop, in the start menu or in its programs submenu.
It will both check in the user's private desktop/ start menu.. as in
the all-users settings.
The return value shows where the first installation was found,
it may be used as in .FormCreate() at the bottom of the example.
Because shortcuts are just files, it is not case-sensitive.
LinkExists ('SourceCoder') = LinkExists ('sourcecoder')
 | |  | | uses
Registry;
type
TInstallationPlace = (le_None, le_CommonDesktop, le_CommonProgs, le_CommonStart,
le_UserDesktop, le_UserProgs, le_UserStart);
function LinkExists (const s : String) : TInstallationPlace;
var
cDesktop,
cProgs,
cStart,
uDesktop,
uProgs,
uStart : String;
function myExists(const s : String): boolean;
begin
myExists := FileGetAttr(s) >= 0;
end;
begin
cDesktop := '';
cProgs := '';
cStart := '';
uDesktop := '';
uProgs := '';
uStart := '';
with TRegistry.Create do
begin
RootKey:=HKEY_LOCAL_MACHINE;
if OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', false) then
begin
cDesktop := ReadString('Common Desktop');
cProgs := ReadString('Common Programs');
cStart := ReadString('Common Start Menu');
end;
CloseKey;
RootKey:=HKEY_CURRENT_USER;
if OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', false) then
begin
uDesktop := ReadString('Desktop');
uProgs := ReadString('Programs');
uStart := ReadString('Start Menu');
end;
CloseKey;
Free;
end;
Result := le_None;
s := '\' + s;
if myExists(cDesktop + s) then Result := le_CommonDesktop
else
if myExists(cProgs + s) then Result := le_CommonProgs
else
if myExists(cStart + s) then Result := le_CommonStart
else
if myExists(cDesktop + ChangeFileExt(s, '.lnk')) then Result := le_CommonDesktop
else
if myExists(cProgs + ChangeFileExt(s, '.lnk')) then Result := le_CommonProgs
else
if myExists(cStart + ChangeFileExt(s, '.lnk')) then Result := le_CommonStart
else
if myExists(uDesktop + s) then Result := le_UserDesktop
else
if myExists(uProgs + s) then Result := le_UserProgs
else
if myExists(uStart + s) then Result := le_UserStart
else
if myExists(uDesktop + ChangeFileExt(s, '.lnk')) then Result := le_UserDesktop
else
if myExists(uProgs + ChangeFileExt(s, '.lnk')) then Result := le_UserProgs
else
if myExists(uStart + ChangeFileExt(s, '.lnk')) then Result := le_UserStart
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if LinkExists ('SourceCoder') <> le_None then
ShowMessage('yes')
else
ShowMessage('no');
end;
| |  | |  |
Comments:
|