Make a program only run once per Windows session (Views: 102)


How can I prevent the user from running my program twice during the same Windows session? I want to force the user to log into Windows again before my application can be started a second time.


A way to make a program only be able to run once in every session is to create a unique global atom string on first run. Then on the following run, check if the string exists, and not run the program if the string atom is present. For example:

procedure TForm1.FormShow(Sender: TObject);
  atom: Integer;
  if (GlobalFindAtom('This_is_some_unique_text') = 0) then
    atom := GlobalAddAtom('This_is_some_unique_text')
    ShowMessage('This application can only be run once for every Windows Session.');

<< Back to main page