AnsiString __fastcall GetSystemFolder(AnsiString Value)
{
TRegistry *R = new TRegistry();
R->RootKey = HKEY_CURRENT_USER;
AnsiString Res;
try{
R->OpenKeyReadOnly("\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders");
Res = R->ReadString(Value);
if(1 <= Res.AnsiPos("%USERPROFILE%")){
char buf[MAX_PATH];
GetEnvironmentVariable("USERPROFILE",buf,MAX_PATH);
Res = ReplaceText(Res,"%USERPROFILE%",buf);
}
}catch(...){
}
if(Res.IsEmpty()){
try{
R->OpenKeyReadOnly("\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
Res = R->ReadString(Value);
}catch(...){
}
}
if(!Res.IsEmpty() && Res[Res.Length()] != '\\'){
Res += '\\';
}
delete R;
return Res;
}