I ran into this example for locking Windows workstation:
using System.Runtime.InteropServices; ... [DllImport(\"user32.dll\", SetLastError = true)] static ex
No there is not. This is the best way to achieve this action.
Even if it was provided in the BCL, its implementation would almost certainly be identical to your sample. It's not something the CLR would natively implement.