logonuser win95

From: Stéphane Lusignan (slusignan_at_softinfo.ca)
Date: 01/28/05


Date: Fri, 28 Jan 2005 15:13:48 -0500

i Want to ready a file in a Directory where the current user loggin in
Windows have no access !

I want to the same in Win95 and Win98 !!!! I always got the error 120 "Only
valid in Win32 mode".

This code works in WinXP :

  If LogonUser(pchar(edit3.text),pchar(Edit1.text),pchar(edit2.text),
LOGON32_LOGON_INTERACTIVE ,LOGON32_PROVIDER_DEFAULT,phToken) then
  begin
    try
      ImpersonateLoggedOnUser(phToken); // Now application is running as
"userB"
      GetUserName(@lpBuffer,nSize);
      Caption := lpBuffer;
      //ShowMessage(lpBuffer); // I see "userB" , It is OK

      temp1 := TMemoryStream.Create;
      temp1.LoadFromFile(edit4.Text);

      temp := TStringList.Create;

      temp.LoadFromStream(Temp1);

      showmessage(temp.text);

      temp1.Free;
      temp.Free;
    except
    on E:Exception do
      showmessage(e.message);
    end;
  end
  else
    RaiseLastOSError;

Thanks
LuZ