Reputation: 17775
Is there a .Net API or DLL I could call to log another user off in Windows 7?
There are a couple questions on SO already, but they seem to be specific to Windows XP. I've tried them nonetheless and could not get them to work.
Such as this one, and this one.
Is this not possible in Windows 7? Or is there another API that I should be calling?
Upvotes: 0
Views: 1033
Reputation: 8748
If all else fails, you could just call logoff.exe http://ss64.com/nt/logoff.html
but I agree that seems like a dirty quickfix
Upvotes: 0
Reputation: 151
Have you tried this Function? You have to list out the session info first:
[DllImport("wtsapi32.dll", SetLastError = true)]
static extern bool WTSLogoffSession(IntPtr hServer, int SessionId, bool bWait);
Upvotes: 1
Reputation: 6553
Do you have FastUserSwitching turned off? I've noticed that if it is off, you can't force someone to log off by attempting to login (even as administrator). If it is off, try turning it on and see if your program works.
Upvotes: 0