Topic: Application already running
hello friends.. i need script to close application if already running...
My Visual Database → General → Application already running
hello friends.. i need script to close application if already running...
Hi Blackpearl8543,
I don't know how to close an MVD program by checking Windows processes as I don't think th ePascal Script allows access to the THandle type.
However, if you have your users 'login' then you can use the following script .
//user_log.pas
var
logged_in : boolean = False;
procedure ClearLogs;
begin
SqlExecute('DELETE FROM user_log WHERE username = "' + Application.User.Username + '"');
end;
procedure startLogs;
begin
If SqlExecute('SELECT count(username) FROM user_log WHERE username = "' + Application.User.Username + '"') > 0 then
Begin
MessageBox(Application.User.Username + ' is already logged in.' + #13#10#13#10 + 'If this is not correct, please see your administrator.','Login Problem',MB_OK+MB_ICONERROR);
frmMain.Close;
End;
frmMain.lbMainUser.Caption := 'Current User is: ' +Application.User.First_name + ' ' + Application.User.Last_name+' Role: '+Application.User.Role+' Last Login: '+DateToStr(Application.User.Last_Login);
SqlExecute('INSERT INTO user_log (username,Logged_In,isLogged_In) VALUES ("' + Application.User.Username + '","' + FormatDateTime('YYYY-MM-DD hh:nnampm',Application.User.last_login) +'",1)');
logged_in := True;
end;
procedure frmMain_tgLogged_OnCellDoubleClick (Sender: TObject; ACol, ARow: Integer);
begin
showmessage(frmMain.tgLogged.Cells[ACol,ARow] +' '+frmMain.tgLogged.sqlValue);
SqlExecute('Delete FROM user_log WHERE username = "' + frmMain.tgLogged.sqlValue + '"');
end;
begin
end.
You can remove the messagebox code and just go straight to formMain.Close
thanks for help CDB.. but i need application Already running notification... can anyone help .please
Try this
const
APP_NAME = 'My App Name';
procedure Form1_OnShow (Sender: string; Action: string);
begin
Form1.Caption := '';
if FindWindow(nil, APP_NAME) <> 0 then
begin
ShowMessage('This application is already opened, you cannot open it again.".');
Form1.Close;
end;
Form1.Caption := APP_NAME;
end;
Bundle of Thankssssss ehwagner]
I can't get the above code to work for me.
I am using the Login form and have inserted the above code in the global begin....end.
It doesn't matter if I have the code at the beginning or end of the code block, what I get on startup is the message telling me the program is already running, even on first instance. It then goes on to open the login form and opens the main form.
If I move the code into my Mainfrm.show it ignores the code completely.
begin
frmdbCoreLogin.Caption := 'Workshop Parts Login';
{logo is copyright free from https://unsplash.com/photos/jXd2FSvcRr8 }
frmdbCoreLogin.Image1.Picture.loadfromfile((ExtractFilePath(Application.ExeName)+ 'WOS_login.jpg'));
if FindWindow(nil, 'workshopPartsDB') <> 0 then
begin
showmessage('already running');
frmdbCoreLogin.Close;
end;
I have even tried :
if FindWindow(nil, ExtractFileName(Application.ExeName)) <> 0 then
begin
showmessage('already running');
frmdbCoreLogin.Close;
end;
And that doesn't work at all!
I have just had a further fiddle and checked the result of the FindWindow function, and, it is always 0, so no wonder the code doesn't work.
I'm running on Windows 10 64bit.
Sometime it works.. You can Check on Calculator ... But i Want to check that sql server is running or not.. and this code does not works on sql server running state
My Visual Database → General → Application already running
Powered by PunBB, supported by Informer Technologies, Inc.
Theme Hydrogen by Kushi