在C#中以编程方式锁定Windows工作站

Ron*_*ein 16 c# windows pinvoke pure-managed

我遇到了锁定Windows工作站的示例:

using System.Runtime.InteropServices;
...
[DllImport("user32.dll", SetLastError = true)]
static extern bool LockWorkStation();

...
if (!LockWorkStation())
    throw new Win32Exception(Marshal.GetLastWin32Error()); // or any other thing
Run Code Online (Sandbox Code Playgroud)

这个片段有一个纯粹的托管替代方案吗?即,没有P-Invoke.

Jar*_*Par 18

不,那里没有.这是实现此操作的最佳方式.

即使它是在BCL中提供的,它的实现几乎肯定与您的样本相同.这不是CLR原生实现的东西.