Prohibit a user from performing concurrent logins for a PowerBuilder App

Posted on 2001-07-19
Medium Priority
Last Modified: 2013-12-26
I am building security into a system that contains 3 different PowerBuilder applications ( 3 different exe's). I would like to know how I can prohibit a user from launching a second instance of the same executable. I understand that there is a way using Microsoft's API to find out if a particular executable is in the computer's memory.

I am currently using Microsoft's API to obtain the computer name and user name of the person logged onto the computer.

I would like the PowerBuilder application to check the computer's memory to ensure the same exe is not currently running prior to displaying the login screen to the application.

Being a novice developer, I would greatly appreciate it if you could provide code samples.
Question by:frank_s

Expert Comment

ID: 6298638
For the PB 6.5 online help :

On Windows 95 and Windows NT, the Handle function does not return a useful value when the previous flag is TRUE. You can use the FindWindowA Windows function to determine whether a Windows application is already running.

* Declare FindWindowA as a global external function:

FUNCTION uint FindWindowA (long classname,  string windowname) LIBRARY "user32.dll"

* Then add code like the following to your application's open event:

uint  val

val = FindWindowA(0, "MyApp Main Window")

IF val > 0 THEN
     MessageBox("Application already running", "MyApp is already running. You cannot      start it again")

Expert Comment

ID: 6298909
Easiest way to make a section in your INI file [Application] and when application starts,  put the value to 1
App_A=1 , in close event of application to 0 ( App_A=0 ) in your INI file and so on.

MOST IMPORTANT*** If your program crashed INI file remain unchange. INI file changing can be develpoed in error Event.

You can recognise which appl. is running and which Appl. not.

check it also.

Author Comment

ID: 6299336

Does FindWindow work in 5.0?

I put the code in, but it did not work.
Can you see anything I did wrong?

Here is what I put in:
Global External Function
FUNCTION uint FindWindowA(long classname, string windowname) LIBRARY "user32.DLL"

In the Application Open Event:
uint val

val = FindWindowA(0,"w_cdr_frame")

if val > 0 then
     MessageBox("Application already running", "Security is already running")
     gs_ini_file = "cdr.ini"
     OpenWithParm(w_login,"cdr_rept/Administration Report")
     if Message.DoubleParm =1 then
          gw_frame.ia_app = this
     end if
end if

Thanks for all your help.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions


Accepted Solution

holvoet earned 400 total points
ID: 6299612
The second argument to the findwindow function is the window title,
not the internal PB window name.


Author Comment

ID: 6303366
Question for PowerBuilder 5.0.04

I need to get the IP Address of a local computer.
I know how to get to the IP Address in the Registry.
The problem is the IP Address is in a hexadecimal form.
How do I get the hexadecimal into a variable?
How do I convert the hexadecimal back to a standard IP Address?


Expert Comment

ID: 6311174

If you don't like the FindWindow approach, because you don't have a fix title, you can use the CreateMutex function. This function creates a NEW mutex process if doesn't exists, or just opens a handle to the existing one otherwise:

//[external function declaration]
 FUNCTION ulong CreateMutexA(ulong lpMutexAttributes, boolean bInitialOwner, REF string lpszName) &
    LIBRARY "kernel32.dll"
 FUNCTION long GetLastError() LIBRARY "kernel32.dll"
 FUNCTION long CloseHandle(ulong w_handle) LIBRARY "Kernel32.dll"

//[var declaration]
 ulong ziul_mutex

//on the app::open event

 constant ulong ERROR_ALREADY_EXISTS = 183
 constant ulong SUCCESSFUL_EXECUTION = 0

 ulong lpsa
 ulong lul_last_error
 boolean lb_ret = FALSE

 IF NOT (Handle(GetApplication()) = 0) THEN
     ziul_mutex = CreateMutexA(lpsa, FALSE, as_appname)
     lul_last_error = GetLastError()
     IF lul_last_error = ERROR_ALREADY_EXISTS THEN
         //the mutex already exists so give a message and close the app
         messagebox("", "App alrady running")
         HALT CLOSE
     END IF

//on the app::close event
//destroy the created handle

Expert Comment

ID: 6396493

Suggest you to start a new session for the new question.


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question