简体   繁体   English

使用Windows 7 Home Premium的C#注销特定用户?

[英]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? 我可以调用.Net API或DLL来注销Windows 7中的另一个用户吗?

There are a couple questions on SO already, but they seem to be specific to Windows XP. 关于SO已经有几个问题,但是它们似乎特定于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? 在Windows 7中不可能吗? Or is there another API that I should be calling? 还是我应该调用另一个API?

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? 您是否关闭了FastUserSwitching? 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 如果所有其他方法均失败,则可以只调用logoff.exe http://ss64.com/nt/logoff.html

but I agree that seems like a dirty quickfix 但我同意这似乎是一个肮脏的快速修复方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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