Solved

Prohibit a user from performing concurrent logins for a PowerBuilder App

Posted on 2001-07-19
7
571 Views
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.
0
Comment
Question by:frank_s
7 Comments
 

Expert Comment

by:holvoet
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")
     HALT CLOSE
ELSE
     open(w_main)
END IF
0
 
LVL 4

Expert Comment

by:Bhatti
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.
0
 

Author Comment

by:frank_s
ID: 6299336
holvoet,

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:
Declare
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")
     HALT CLOSE
else
     gs_ini_file = "cdr.ini"
     OpenWithParm(w_login,"cdr_rept/Administration Report")
     if Message.DoubleParm =1 then
          open(gw_frame)
          gw_frame.ia_app = this
     else
          Halt
     end if
end if

Thanks for all your help.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Accepted Solution

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

HTH,
Jo
0
 

Author Comment

by:frank_s
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?

Thanks,
   Frank
0
 

Expert Comment

by:igarab
ID: 6311174
Hi,

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]
 Private:
 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
 END IF

//on the app::close event
//destroy the created handle
CloseHandle(ziul_mutex)
0
 

Expert Comment

by:kokan
ID: 6396493
Frank,

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

Ken.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

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: …
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 columnThat will then direct you to their download page.From that page s…
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.

770 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