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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

690 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