Solved

How to find CommonAppData folder?

Posted on 2010-08-26
8
7,932 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
Technology Partners: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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