I use a function which uses the SHGetSpecialFolderLocation Windows API
function.
function GetSpecialFolder(const FolderId: integer): string;
var
ppidl : PItemIdList;
begin
if SHGetSpecialFolderLocation(Application.MainForm.Handle,FolderId,ppidl)
= NOERROR then
begin
SetLength(Result,MAX_PATH);
if SHGetPathFromIDList(ppidl,PChar(Result)) then
SetLength(Result,StrLen(PChar(Result)))
else
Result := '';
end
else Result := '';
end;
Then you need to call it with the a CSIDL_ constant as defined in ShlObj.pas
such as CSIDL_APPDATA. Here is a list I found on the internet.
CSIDL_DESKTOP = $0; //(desktop)
CSIDL_INTERNET = $1; //Internet Explorer (icon on desktop)
CSIDL_PROGRAMS = $2; //Start Menu\Programs
CSIDL_CONTROLS = $3; //My Computer\Control Panel
CSIDL_PRINTERS = $4; //My Computer\Printers
CSIDL_PERSONAL = $5; //My Documents
CSIDL_FAVORITES = $6; //(user)\Favourites
CSIDL_STARTUP = $7; //Start Menu\Programs\Startup
CSIDL_RECENT = $8; //(user)\Recent
CSIDL_SENDTO = $9; //(user)\SendTo
CSIDL_BITBUCKET = $A; //(desktop)\Recycle Bin
CSIDL_STARTMENU = $B; //(user)\Start Menu
CSIDL_DESKTOPDIRECTORY = $10; //(user)\Desktop
CSIDL_DRIVES = $11; //My Computer
CSIDL_NETWORK = $12; //Network Neighbourhood
CSIDL_NETHOOD = $13; //(user)\nethood
CSIDL_FONTS = $14; //windows\fonts
CSIDL_TEMPLATES = $15;
CSIDL_COMMON_STARTMENU = $16; //All Users\Start Menu
CSIDL_COMMON_PROGRAMS = $17; //All Users\Programs
CSIDL_COMMON_STARTUP = $18; //All Users\Startup
CSIDL_COMMON_DESKTOPDIRECTORY = $19;//All Users\Desktop
CSIDL_APPDATA = $1A; //(user)\Application Data
CSIDL_PRINTHOOD = $1B; //(user)\PrintHood
CSIDL_LOCAL_APPDATA = $1C; //(user)\Local Settings\Application
Data (non roaming)
CSIDL_ALTSTARTUP = $1D; //non localized startup
CSIDL_COMMON_ALTSTARTUP = $1E; //non localized common startup
CSIDL_COMMON_FAVORITES = $1F;
CSIDL_INTERNET_CACHE = $20;
CSIDL_COOKIES = $21;
CSIDL_HISTORY = $22;
CSIDL_COMMON_APPDATA = $23; //All Users\Application Data
CSIDL_WINDOWS = $24; //GetWindowsDirectory()
CSIDL_SYSTEM = $25; //GetSystemDirectory()
CSIDL_PROGRAM_FILES = $26; //C:\Program Files
CSIDL_MYPICTURES = $27; //C:\Program Files\My Pictures
CSIDL_PROFILE = $28; //USERPROFILE
CSIDL_SYSTEMX86 = $29; //x86 system directory on RISC
CSIDL_PROGRAM_FILESX86 = $2A; //x86 C:\Program Files on RISC
CSIDL_PROGRAM_FILES_COMMON = $2B; //C:\Program Files\Common
CSIDL_PROGRAM_FILES_COMMONX86 = $2C; //x86 Program Files\Common on RISC
CSIDL_COMMON_TEMPLATES = $2D; //All Users\Templates
CSIDL_COMMON_DOCUMENTS = $2E; //All Users\Documents
CSIDL_COMMON_ADMINTOOLS = $2F; //All Users\Start
Menu\Programs\Administrative Tools
CSIDL_ADMINTOOLS = $30; //(user)\Start
Menu\Programs\Administrative Tools
CSIDL_FLAG_CREATE = $8000; //combine with CSIDL_ value to force
create on SHGetSpecialFolderLocation()
CSIDL_FLAG_DONT_VERIFY = $4000; //combine with CSIDL_ value to force
create on SHGetSpecialFolderLocation()
CSIDL_FLAG_MASK = $FF00; //mask for all possible flag values
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of John Bird
Sent: Monday, 18 June 2007 21:00
To: 'NZ Borland Developers Group - Delphi List'
Subject: RE: [DUG] Anyone need XP Pro?
Vista:
I have not actually worked day to day yet in Vista, but two things I see
about it I am all in favour of.
1 - UAC - as a long time Unix user used to running as a non admin (root)
user I just got used to setting up data folders and ownerships and
permissions. It's a necessary "evil" that is not so hard and best to just
do it and get used to how the OS wants to protect itself and you. Its
always a good programming practice to be able separate programs and settings
files and data files anyway, from what I have found if you have well
specified folders for eg settings then you have maybe just one folder to
make sure you have the approriate write permissions to.
2 - From what I have seen of the Vista folder structures they are a lot
flatter and more easy to find than XP - the huge tree under "Documents and
Settings" I find really obscure and seems to me an exercise in creating
security by making it really hard to find where the actual important files
are likely to be. In fact I got the impression that someone at Microsoft
said "OK lets finally admit that something like the Unix folder structure
makes more sense". Have a Users folder, with usernames under that, and
under each user folder folders for pictures and documents etc - guess where
that comes from.
However the Windows permissions and folder structures are much more complex
and arbitrary to my mind than the logical structures on Unix. I think
that's one of the reasons almost no-one outside of Microsoft got comfortable
with them.
So far I create my own folder structures all under my own folder (which is
NOT under Program Files) so I can set the permissions on these without
upsetting anything else.
However it would be tidier to follow the conventions - its usually easier to
swim with the stream than against it!
Question:
I remember once coming across a Delphi unit that can return all the Windows
folder settings for almost everything (temp files, program files, Windows
folder, Start menu user, Start menu all users, etc etc). Can't find it!
Does anyone know of a version that gives the locations for all common
versions (98, 2000, XP and Vista)? That would be an excellent level of
abstraction to add to any program.
Anyone have or know of such a unit/utility/component?
John
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: [email protected]
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to [EMAIL PROTECTED] with Subject: unsubscribe