Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to check whether a user has a shortcut installed Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
15-Sep-02
Category
Shell API
Language
Delphi All Versions
Views
127
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: William Gerbert

Check whether a user has a shortcut installed

Answer:

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')

1   uses
2     Registry;
3   
4   type
5     TInstallationPlace = (le_None, le_CommonDesktop, le_CommonProgs, le_CommonStart,
6       le_UserDesktop, le_UserProgs, le_UserStart);
7   
8     // check whether a shortcut or a file with name s is either on
9     // the desktop, in the start menu or in its programs submenu.
10  
11  function LinkExists(const s: string): TInstallationPlace;
12  var
13    cDesktop,
14      cProgs,
15      cStart,
16      uDesktop,
17      uProgs,
18      uStart: string;
19  
20    function myExists(const s: string): boolean;
21    begin
22      // s can be directory or a file, so FileExists() won't do it..
23      myExists := FileGetAttr(s) >= 0;
24    end;
25  
26  begin
27    // check whether we have the link in All_User's Desktop!
28    cDesktop := '';
29    cProgs := '';
30    cStart := '';
31    uDesktop := '';
32    uProgs := '';
33    uStart := '';
34    with TRegistry.Create do
35    begin
36      RootKey := HKEY_LOCAL_MACHINE;
37      if OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
38        false) then
39      begin
40        cDesktop := ReadString('Common Desktop');
41        cProgs := ReadString('Common Programs');
42        cStart := ReadString('Common Start Menu');
43      end;
44      CloseKey;
45      RootKey := HKEY_CURRENT_USER;
46      if OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
47        false) then
48      begin
49        uDesktop := ReadString('Desktop');
50        uProgs := ReadString('Programs');
51        uStart := ReadString('Start Menu');
52      end;
53      CloseKey;
54      Free;
55    end;
56    // check in all 3 places for our link
57    Result := le_None;
58    s := '\' + s;
59    if myExists(cDesktop + s) then
60      Result := le_CommonDesktop
61    else if myExists(cProgs + s) then
62      Result := le_CommonProgs
63    else if myExists(cStart + s) then
64      Result := le_CommonStart
65    else if myExists(cDesktop + ChangeFileExt(s, '.lnk')) then
66      Result := le_CommonDesktop
67    else if myExists(cProgs + ChangeFileExt(s, '.lnk')) then
68      Result := le_CommonProgs
69    else if myExists(cStart + ChangeFileExt(s, '.lnk')) then
70      Result := le_CommonStart
71    else if myExists(uDesktop + s) then
72      Result := le_UserDesktop
73    else if myExists(uProgs + s) then
74      Result := le_UserProgs
75    else if myExists(uStart + s) then
76      Result := le_UserStart
77    else if myExists(uDesktop + ChangeFileExt(s, '.lnk')) then
78      Result := le_UserDesktop
79    else if myExists(uProgs + ChangeFileExt(s, '.lnk')) then
80      Result := le_UserProgs
81    else if myExists(uStart + ChangeFileExt(s, '.lnk')) then
82      Result := le_UserStart
83  end;
84  
85  procedure TForm1.FormCreate(Sender: TObject);
86  begin
87    if LinkExists('SourceCoder') <> le_None then
88      ShowMessage('yes')
89    else
90      ShowMessage('no');
91  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC