3

We are currently using a report printing application launched by a user-defined function located in a Firebird database which runs as a service.

The UDF consists of a simple DLL that launches the reporting application and pass the report ID to be printed through "CreateProcessAsUser" API.

In details, we are impersonating a particular windows account in order to have access to the user's printer. The computer on which the software is run is never attended. No one actually open a session on it.

So here's how we're doing it:

LogonUser( sUser, nil, sPass, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, hToken );

...

LoadUserProfile(hToken, ProfileInfo);

...

ImpersonateLoggedOnUser(hToken);

...

StartupInfo.lpDesktop := Pchar('Winsta0\Default');

CreateProcessAsUser(hToken,nil, Pchar(sCommand), nil, nil, False, 0, nil, nil, StartupInfo, ProcessInfo);

...

UnloadUserProfile(hToken,ProfileInfo.hProfile);

Now we have moved to windows 7 platform and obviously, it doesn't work anymore.

Is it still possible to impersonate a user account and use his printer from a service under windows vista/7 even if the user is not logged on ? (Otherwise I'd use the user's currently active session ID)

Thanks for your help

Emmanuel .
  • 31
  • 2
  • Does `LogonUserEx` also not work under Windows 7? Was `LogonUser` deprecated in 7? Disable UAC and see if your code still fails. – cfeduke Sep 26 '11 at 21:06
  • What part of it doesn't work? LogonUser? LoadUserProfile? CreateProcessAsUser? What errors are you getting? – Luke Sep 26 '11 at 21:46
  • Well, All the API calls return true so it looks like the problem lies in the launched application itself instead. The application seems to hang when dynamically creating the first form object. – Emmanuel . Sep 27 '11 at 14:19

0 Answers0