Thanks for posting your question in the Microsoft Q&A forum.
Use the LockWorkStation
function provided by the Windows API to lock the computer programmatically.
You can call this function when the user attempts to close the form without submitting it, effectively preventing further use of the computer until the form is completed.
using System.Runtime.InteropServices;
class Program
{
[DllImport("user32.dll", SetLastError = true)]
static extern bool LockWorkStation();
static void Main(string[] args)
{
// Call LockWorkStation to lock the computer
LockWorkStation();
}
}
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful