I have a program that runs as a scheduled task. The program runs on XP as SYSTEM. The idea is that the program will run in the background, while USER is active.
I need the program to logoff USER when specific conditions occur.
I tried using:
[DllImport("user32.dll")]
public static extern int ExitWindowsEx(int uFlags, int dwReason);
but that appears to not log USER off.
I think maybe it's logging SYSTEM off, as it is running as SYSTEM.
How can i logogg USER?
Thanks, SummerBulb.
It would help if you showed the flags for
ExitWindowsEx,but you may need to impersonate the user, though I think this is unlikely. If I remember logging off the current user was enough, but you may have to force the logoff, as it can be cancelled otherwise, if the user hasn't saved some changes for example.But to impersonate a user you can look at this: http://www.codeproject.com/KB/system/UserImpersonation.aspxI would start with looking here, and include both the logoff and forceifhung values: http://msdn.microsoft.com/en-us/library/aa376868(VS.85).aspx
It would be similar to
EWX_FORCEIFHUNG | EWX_LOGOFFas the parameter.UPDATE:
I expect Mike is correct that impersonation won't help here.