Title: Finding special folders of the shell
Question: Sometimes it is necessary to find some special shell folder like
Programs, Start Menu, Startup, Favorites or other.
Answer:
This can be easy found in the registry. Dont forget to bind the
unit Registry to your uses clause.
const cShellAppData = 'AppData';
cShellCache = 'Cache';
cShellCookies = 'Cookies';
cShellDesktop = 'Desktop';
cShellFavorites = 'Favorites';
cShellFonts = 'Fonts';
cShellHistory = 'History';
cShellLocalApp = 'Local AppData';
cShellNetHood = 'NetHood';
cShellPersonal = 'Personal';
cShellPrintHood = 'PrintHood';
cShellPrograms = 'Programs';
cShellRecent = 'Recent';
cShellSendTo = 'SendTo';
cShellStartMenu = 'Start Menu';
CShellStartUp = 'Startup';
cShellTemplates = 'Templates';
function GetShellFolder (const folder: string):string;
const cWin32 = 'SOFTWARE\Microsoft\Windows\CurrentVersion';
cSHellPrefix = '\Explorer\Shell Folders';
var r: TRegistry;
begin
Result:= '';
r:= TRegistry.Create;
try
r.Rootkey:=HKEY_CURRENT_USER;
// Make no difference between NT and 95/98!
if r.OpenKey (cWin32 + cShellPrefix, False) then
Result:= r.ReadString (folder) + '\';
finally
r.Free;
end;
end;
Example: To get the "Program Files" folder simply call
folder:= GetShellFolder (cShellPrograms);