private void FormTerminal_Load(object sender, EventArgs e) { Size = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size; Location = new Point(0, 0); labelConnection.Visible = false; _listSheets = new List <Sheet>(); if (IsSimpleMode) { //PatNum set externally (in FormPatientForms) return; } //NOT SimpleMode from here down Process processCur = Process.GetCurrentProcess(); //Delete all terminalactives for this computer, except new one, based on CompName and SessionID TerminalActives.DeleteForCmptrSessionAndId(Environment.MachineName, processCur.SessionId, excludeId: processCur.Id); string clientName = null; string userName = null; try { clientName = Environment.GetEnvironmentVariable("ClientName"); userName = Environment.GetEnvironmentVariable("UserName"); } catch (Exception) { //user may not have permission to access environment variables or another error could happen } if (string.IsNullOrWhiteSpace(clientName)) { //ClientName only set for remote sessions, try to find suitable replacement. clientName = userName; if (processCur.SessionId < 2 || string.IsNullOrWhiteSpace(userName)) { //if sessionId is 0 or 1, this is not a remote session, use MachineName clientName = Environment.MachineName; } } if (string.IsNullOrWhiteSpace(clientName) || TerminalActives.IsCompClientNameInUse(Environment.MachineName, clientName)) { InputBox iBox = new InputBox("Please enter a unique name to identify this kiosk."); iBox.setTitle(Lan.g(this, "Kiosk Session Name")); iBox.ShowDialog(); while (iBox.DialogResult == DialogResult.OK && TerminalActives.IsCompClientNameInUse(Environment.MachineName, iBox.textResult.Text)) { MsgBox.Show(this, "The name entered is invalid or already in use."); iBox.ShowDialog(); } if (iBox.DialogResult != DialogResult.OK) { DialogResult = DialogResult.Cancel; return; //not allowed to enter kiosk mode unless a unique human-readable name is entered for this computer session } clientName = iBox.textResult.Text; } //if we get here, we have a SessionId (which could be 0 if not in a remote session) and a unique client name for this kiosk TerminalActive terminal = new TerminalActive(); terminal.ComputerName = Environment.MachineName; terminal.SessionId = processCur.SessionId; terminal.SessionName = clientName; terminal.ProcessId = processCur.Id; TerminalActives.Insert(terminal); //tell the database that a terminal is newly active on this computer Signalods.SetInvalid(InvalidType.Kiosk, KeyType.ProcessId, processCur.Id); //signal FormTerminalManager to re-fill grids timer1.Enabled = true; }