Solved

How to find CommonAppData folder?

Posted on 2010-08-26
8
7,546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
LAN or WAN ? 11 116
Delphi...Split view - idea? 1 139
firemonkey keyboard covers the controls 1 78
Delphi: barcode reading on android platform 1 96
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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