It would be better if you looked for the API message that closes the window (Most likely WM_NCCLOSE) and cancel it out.
That would be your best bet, as
nothing would be able to close the window while your script intercepts and terminates this message.
I grabbed this from a Delphi forum, which you could probably use in a DLL and call the function from your script. Take note of the
bolded pieces of code.
code:
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
answer : string;
begin
answer := InputBox('Admin password?','password', '');
if answer='yourpassword' then canclose:=true
else
canclose:=false;
end;
Like I said before, it's not going to be easy initially, but it's quite easy to understand and it's well worth the effort.