September 26th, 2009, 01:34 PM
How to programatically Logoff interactive user and Logon as another [C#]
Is there a way to force a logoff (knowing this is not recommended) of the current interactive (logged-on) user and then login with a new user account (interactive - not using stuff like LogonUser and other impersonation tricks) to simulate someone physically pressing LOGOFF and then selecting a new account to LOGON...?
The issue is that my service creates a new user account programatically - and I need to find a way to create its corresponding user profile. From what I can see the only way that works would be to physically logoff the current user, and then login as the new user (which will create the User Profile for HKCU, Documents & Settings, etc...). Sounds a little crazy but I can't find a better way...
So, I need to find a way to programmatically force the logoff & logon actions (from my running Windows Service under LocalSystem) - I have all the credentials and access rights needed ... Are there system function calls I can use?
For Logoff I think I can use WTSLogoffSession(...), still trying to get it to work but seems promising - however I have no clue what to do about logon...
Alternitively if there is a better approach to solve my problem I am all ears
Any help or hints would be much appreciated...
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.