Solved

How to find CommonAppData folder?

Posted on 2010-08-26
8
5,976 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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