Prohibit a user from performing concurrent logins for a PowerBuilder App

Posted on 2001-07-19
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.
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.


Accepted Solution

holvoet earned 100 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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 new code templates in NetBeans IDE 8.0 for Windows.

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now