uses
Registry;
type
TInstallationPlace = (le_None, le_CommonDesktop, le_CommonProgs, le_CommonStart,
le_UserDesktop, le_UserProgs, le_UserStart);
// check whether a shortcut or a file with name s is either on
// the desktop, in the start menu or in its programs submenu.
function LinkExists (const s : String) : TInstallationPlace;
var
cDesktop,
cProgs,
cStart,
uDesktop,
uProgs,
uStart : String;
function myExists(const s : String): boolean;
begin
// s can be directory or a file, so FileExists() won't do it..
myExists := FileGetAttr(s) >= 0;
end;
begin
// check whether we have the link in All_User's Desktop!
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;
// check in all 3 places for our link
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;
-----------------------
这下子该满意了吧?