Run application only once per windows-session
Using this simple tip, you can block your application to be executable only once per windows sessions. To run application again, Windows must be restarted before.
We will use “atom”, which is something like global identifier. Using function GlobalFindAtom, we will try to find our application’s unique ID (we will generate a GUID using Ctrl+Shift+G shortcut). If it doesn’t exist, we will allow to run application and create “atom” using GlobalAddAtom function. And that is all.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormShow(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormShow(Sender: TObject); begin if GlobalFindAtom('{92859177-BAA9-45B7-9A21-07F1BA3C1CA5}') = 0 then GlobalAddAtom('{92859177-BAA9-45B7-9A21-07F1BA3C1CA5}') else begin ShowMessage('This application can be started only once per Windows '+ 'session, you need to restart system to run program again.'); Close; end; end; end. |