/// <summary> /// Start process protection /// </summary> private void LockProcess() { int myPid = Process.GetCurrentProcess().Id; if (previousProtectionPID == -1) { Process protectorProcess = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo { FileName = System.Windows.Forms.Application.ExecutablePath, Arguments = $"protect {myPid}" }; protectorProcess.StartInfo = startInfo; protectorProcess.Start(); locker.StartProtectProcess(protectorProcess.Id, $"protect {myPid}"); } else { locker.StartProtectProcess(previousProtectionPID, $"protect {myPid}"); } }
/// <summary> /// Form Shown Event Handler /// </summary> /// <param name="sender">Sender</param> /// <param name="e">EventArgs</param> private void Form1_Shown(object sender, EventArgs e) { string[] arguments = Environment.GetCommandLineArgs(); int protectPid = -1; if (arguments.Length == 3 && arguments[1] == "protect") { protectPid = (int.TryParse(arguments[2], out int result)) ? result : -1; } if (protectPid == -1) { #if DEBUG LoadDebugWindow(); #endif //LoadToTraybar(); qrCodeGenerator = new QRGenerator(); qrCodeGenerator.SetData(AndroidServer.GetLocalIPAddress(), 9624); LoadKeyGeneration(); LoadAndroidServer(); LoadJavascriptServer(); int protectorPID = -1; if (arguments.Length == 3 && arguments[1] == "lock") { protectorPID = (int.TryParse(arguments[2], out int result)) ? result : -1; if (!WindowsLocking.CanLock()) { protectorPID = -1; } } systemLocking = new WindowsLocking(qrCodeGenerator, androidServer, protectorPID); if (protectorPID != -1) { androidServer.SendLockSignal(); } if (arguments.Length == 2 && arguments[2] == "forcelock" && WindowsLocking.CanLock()) { androidServer.SendLockSignal(); } } else { Hide(); ProcessLocker locker = new ProcessLocker(); locker.StartProtectProcess(protectPid, $"lock {System.Diagnostics.Process.GetCurrentProcess().Id}"); } }