[研究][C#]Log Off the Current User
2022-04-24
環境:Visual Studio 2022 + WinForm + C# + Wndows Server 2019 排程
LogOffCurrentUser.cs
using System.Runtime.InteropServices; namespace LogOffCurrentUser { internal class Program { [DllImport("user32.dll")] public static extern int ExitWindowsEx(int operationFlag, int operationReason); static void Main(string[] args) { ExitWindowsEx(0, 0); } } } |
但是實際測試,排程有啟動它,工作管理員有出現該程式,但使用者沒有被登出。
可改用下面方法。
[研究]排程 shutdown.exe 登出某使用者 (Windows Server 2019)
https://shaurong.blogspot.com/2022/04/shutdownexe-windows-server-2019.html
(完)
相關
How to Log Off the Current User - Win32 apps | Microsoft Docs
https://docs.microsoft.com/en-us/windows/win32/shutdown/how-to-log-off-the-current-user
.net - Log off a Windows user locally using c# - Stack Overflow
https://stackoverflow.com/questions/14466373/log-off-a-windows-user-locally-using-c-sharp
沒有留言:
張貼留言