28
Jun 08

Delphi: Utils :: GetShellFolder

:: articles :: by Gilberto Saraiva

Folks,

Get some Shell Folder from Current User or All User ( System ):

 Delphi |  copy code |? 
01
uses Registry;
02
 
03
type
04
  TShellFolderType = (
05
    // User
06
    sftAppData, sftCookies, sftDesktop, sftFavorites,
07
    sftNetHood, sftPersonal, sftPrintHood, sftRecent, sftSendTo, sftStartMenu,
08
    sftTemplates, sftPrograms, sftStartup, sftLocalSettings, sftLocalAppData,
09
    sftCache, sftHistory, sftMyPictures, sftFonts, sftMyMusic, sftCDBurning,
10
    sftMyVideo, sftAdminTools,
11
    // System
12
    sftCommonAppData, sftCommonPrograms, sftCommonDocuments, sftCommonDesktop,
13
    sftCommonStartMenu, sftCommonPictures, sftCommonMusic, sftCommonVideo,
14
    sftCommonFavorites, sftCommonStartup, sftCommonTemplates,
15
    sftCommonAdminTools, sftCommonPersonal);
16
 
17
 
18
function GetShellFolder(AShellFolderType: TShellFolderType): string;
19
begin
20
  with TRegistry.Create do
21
  begin
22
    if AShellFolderType <= sftAdminTools then
23
      RootKey := HKEY_CURRENT_USER
24
    else
25
      RootKey := HKEY_LOCAL_MACHINE;
26
 
27
    OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', True);
28
    case AShellFolderType of
29
      sftAppData       : Result := ReadString('AppData');
30
      sftCookies       : Result := ReadString('Cookies');
31
      sftDesktop       : Result := ReadString('Desktop');
32
      sftFavorites     : Result := ReadString('Favorites');
33
      sftNetHood       : Result := ReadString('NetHood');
34
      sftPersonal      : Result := ReadString('Personal');
35
      sftPrintHood     : Result := ReadString('PrintHood');
36
      sftRecent        : Result := ReadString('Recent');
37
      sftSendTo        : Result := ReadString('SendTo');
38
      sftStartMenu     : Result := ReadString('Start Menu');
39
      sftTemplates     : Result := ReadString('Templates');
40
      sftPrograms      : Result := ReadString('Programs');
41
      sftStartup       : Result := ReadString('Startup');
42
      sftLocalSettings : Result := ReadString('Local Settings');
43
      sftLocalAppData  : Result := ReadString('Local AppData');
44
      sftCache         : Result := ReadString('Cache');
45
      sftHistory       : Result := ReadString('History');
46
      sftMyPictures    : Result := ReadString('My Pictures');
47
      sftFonts         : Result := ReadString('Fonts');
48
      sftMyMusic       : Result := ReadString('My Music');
49
      sftCDBurning     : Result := ReadString('CD Burning');
50
      sftMyVideo       : Result := ReadString('My Video');
51
      sftAdminTools    : Result := ReadString('Administrative Tools');
52
 
53
      // System
54
      sftCommonAppData    : Result := ReadString('Common AppData');
55
      sftCommonPrograms   : Result := ReadString('Common Programs');
56
      sftCommonDocuments  : Result := ReadString('Common Documents');
57
      sftCommonDesktop    : Result := ReadString('Common Desktop');
58
      sftCommonStartMenu  : Result := ReadString('Common Start Menu');
59
      sftCommonPictures   : Result := ReadString('CommonPictures');
60
      sftCommonMusic      : Result := ReadString('CommonMusic');
61
      sftCommonVideo      : Result := ReadString('CommonVideo');
62
      sftCommonFavorites  : Result := ReadString('Common Favorites');
63
      sftCommonStartup    : Result := ReadString('Common Startup');
64
      sftCommonTemplates  : Result := ReadString('Common Templates');
65
      sftCommonAdminTools : Result := ReadString('Common Administrative Tools');
66
      sftCommonPersonal   : Result := ReadString('Personal');
67
    end;                                                     
68
  end;
69
end;

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


Leave a comment