Solved

How to find CommonAppData folder?

Posted on 2010-08-26
8
5,632 Views
Last Modified: 2012-05-10
I’m not clear on how to access the CommonAppDataFolder property from a Delphi program. I haven’t been able to find a command as there is for "GetWindowDirectory," for example. How can I get this information from within my Delphi program?
0
Comment
Question by:efz
  • 4
  • 3
8 Comments
 
LVL 4

Accepted Solution

by:
bjove earned 500 total points
ID: 33533760
Read the location from registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\Shell Folders\Common AppData
0
 
LVL 13

Expert Comment

by:aflarin
ID: 33533799
Path:= SHGetFolderPath(CSIDL_APPDATA);
0
 
LVL 13

Expert Comment

by:aflarin
ID: 33533814
oh, sorry you need common app data:

Path:= SHGetFolderPath(CSIDL_COMMON_APPDATA);
0
 
LVL 13

Expert Comment

by:aflarin
ID: 33533856
function SHGetFolderPath(AFolder: Integer): string;
const
  SHGFP_TYPE_CURRENT  = 0;
  SHGFP_TYPE_DEFAULT  = 1;
var
  Buf: array[0..MAX_PATH-1] of Char;
begin
  Result:= '';
  if SHFolderDLLHandle = 0 then begin
    SHGetFolderPathFunc:= nil;

    SHFolderDLLHandle:= LoadLibrary('shell32.dll');
    if SHFolderDLLHandle <> 0 then
      SHGetFolderPathFunc:= GetProcAddress(SHFolderDLLHandle, 'SHGetFolderPathA');
  end;

  if Assigned(SHGetFolderPathFunc) then
    if SHGetFolderPathFunc(0, AFolder, 0, SHGFP_TYPE_CURRENT, Buf) = S_OK then
      Result:= Buf;
end;
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 14

Expert Comment

by:systan
ID: 33533883
const
  REGSTR_PATH_SPECIAL_FOLDERS   = REGSTR_PATH_EXPLORER + '\Shell Folders';
  CSIDL_DESKTOP                       = $0000;
  CSIDL_INTERNET                      = $0001;
  CSIDL_PROGRAMS                      = $0002;
  CSIDL_CONTROLS                      = $0003;
  CSIDL_PRINTERS                      = $0004;
  CSIDL_PERSONAL                      = $0005;
  CSIDL_FAVORITES                     = $0006;
  CSIDL_STARTUP                       = $0007;
  CSIDL_RECENT                        = $0008;
  CSIDL_SENDTO                        = $0009;
  CSIDL_BITBUCKET                     = $000a;
  CSIDL_STARTMENU                     = $000b;
  CSIDL_DESKTOPDIRECTORY              = $0010;
  CSIDL_DRIVES                        = $0011;
  CSIDL_NETWORK                       = $0012;
  CSIDL_NETHOOD                       = $0013;
  CSIDL_FONTS                         = $0014;
  CSIDL_TEMPLATES                     = $0015;
  CSIDL_COMMON_STARTMENU              = $0016;
  CSIDL_COMMON_PROGRAMS               = $0017;
  CSIDL_COMMON_STARTUP                = $0018;
  CSIDL_COMMON_DESKTOPDIRECTORY       = $0019;
  CSIDL_APPDATA                       = $001a;
  CSIDL_PRINTHOOD                     = $001b;
  CSIDL_ALTSTARTUP                = $001d;         // DBCS
  CSIDL_COMMON_ALTSTARTUP         = $001e;         // DBCS
  CSIDL_COMMON_FAVORITES          = $001f;
  CSIDL_INTERNET_CACHE            = $0020;
  CSIDL_COOKIES                   = $0021;
  CSIDL_HISTORY                   = $0022;
function CommonAppDataProgs: string;

var

   r: Bool;

   path: array[0..Max_Path] of Char;

begin

   r := ShGetSpecialFolderPath(0, path, CSIDL_COMMON_PROGRAMS, False) ;

   Result := Path;

end;





function CommonAppData: string;

var

   r: Bool;

   path: array[0..Max_Path] of Char;

begin

   r := ShGetSpecialFolderPath(0, path, CSIDL_APPDATA, False) ;

   Result := Path;

end;

Open in new window

0
 
LVL 14

Expert Comment

by:systan
ID: 33533912
lol, last time I check theres only bjove
0
 
LVL 14

Expert Comment

by:systan
ID: 33533932
Oh, don't forget the
uses shlobj;
function AppData: string;

var

   r: Bool;

   path: array[0..Max_Path] of Char;

begin

   r := ShGetSpecialFolderPath(0, path, CSIDL_COMMON_APPDATA, False) ;

   Result := Path;

end;

Open in new window

0
 
LVL 14

Expert Comment

by:systan
ID: 33534073
How can I get this information from within my Delphi program?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now