Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to find CommonAppData folder?

Posted on 2010-08-26
8
Medium Priority
?
9,322 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

618 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