You can impersonate a logged on user to access the data folder, using the LogonUser
, ImpersonateLoggedOnUser
and RevertToSelf
functions.
Try this sample
{$APPTYPE CONSOLE}
uses
Windows,
SysUtils;
function ConnectAs(const lpszUsername, lpszPassword: string): Boolean;
var
hToken : THandle;
begin
Result := LogonUser(PChar(lpszUsername), nil, PChar(lpszPassword), LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, hToken);
if Result then
Result := ImpersonateLoggedOnUser(hToken)
else
RaiseLastOSError;
end;
begin
try
ConnectAs('Admin','Password');
//do something here
//terminates the impersonation
RevertToSelf;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
readln;
end.