简体   繁体   中英

log off a specific user with C# for Windows 7 Home Premium?

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?

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);

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM