You probably need to process the WM_QUERYENDSESSION message from Windows in your app.
Where were you 17 years ago when I was struggling big time with this? :-) (And there's still an app of mine in the wild with this problem - can't shutdown a PC with it running)
My code was contained in project1.lpr file, i don't use form so how can i do it?
Errr... Well, essentially you need to intercept all windows messages going to your app, and determine if one is WM_QUERYENDSESSION. The framework is detailed here
http://wiki.lazarus.freepascal.org/Win32/64_Interface#Processing_non-user_messages_in_your_windowBut... Without Forms? Is this a console app? Do console apps even get Windows Messages? I thought the purpose of the console was to do without the overheads of window management. Could just be ancient thinking - I see console app and think DOS. So, really, I've no idea....
Also, there's a big assumption here that you're on Windows. Again - I've absolutely no idea how to do this on other OS's...