Blocking another instance of an application from Running

21 views
Skip to first unread message

rowellmagno

unread,
Jul 8, 2022, 3:04:43 AM7/8/22
to OpenROAD Users Mailing List
Hello,

Is there a way to check when running an Image Application if there is already a running instance, then block running another one.

Would like to make sure users cannot run another instance of the application when it is already running.

regards,
Rowell

Adrian Williamson

unread,
Jul 8, 2022, 3:22:31 AM7/8/22
to openroa...@googlegroups.com

Hi Rowell,

 

I’d be looking at running a task list command – Oh flashback : I think we touched on this recently.

 

Wmic – my new best friend:

C:\WINDOWS\system32>wmic process where "name='w4gldev.exe'" get commandline /format:list

CommandLine="C:\Program Files\Ingres\ingresXH\ingres\bin\w4gldev.exe" "runimage" "workbnch.img" -cclassic -Tmin -Lworkbench.log ""

That way you can work out what image file is being used and make decision.

 

My nefarious brain says – what if they started another cause the first one crashed in a tight loop?

 

Cheers

 

Adrian

--
You received this message because you are subscribed to the Google Groups "OpenROAD Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openroad-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openroad-users/8ea27239-8ab6-49b2-a6ab-a28684939776n%40googlegroups.com.

rowellmagno

unread,
Jul 8, 2022, 3:34:17 AM7/8/22
to OpenROAD Users Mailing List
Hi Adrian,

I'm sorry, I'm really new at this. Having hard time understanding how to use this. 
would I use this on my application Initialization? 

I'm really sorry, 

Rowell

Adrian Williamson

unread,
Jul 8, 2022, 4:08:24 AM7/8/22
to openroa...@googlegroups.com

Morning/Afternoon,

 

No Worries – my fault really, once we get to know you we can get it right.

 

I’m not proofing any of this as I type (think of it as pseudo-code) it is coming from memory and sometime it is not quite right but I hope this nudges you along.

 

I would be running that wmic command from the OpenROAD app with something like a ‘call system’ (in the past people created a 3gl Proc in OpenROAD to map the Windows API ‘Winexec’ function instead, but OpenROAD has evolved)

 

Call System: https://docs.actian.com/openroad/11.2/index.html#page/LangRef/Call_System_Statement.htm

 

Mostly you are trying to avoid a blank DOS box appearing as the app starts up.

 

ProcessWindow Attribute: https://docs.actian.com/openroad/11.2/index.html#page/LangRef/ProcessWindow_Attribute.htm

 

In that command I would re-direct to a file:

 

wmic process where "name='w4glrun.exe'" get commandline /format:list > w4gltasklist.txt

 

So I’ve changed it to be  w4glrun.exe instead of w4gldev.exe and added a redirect.

 

So you have to think – that file I am redirecting to – will there be lots of people logging on to this machine creating contention?

 

Do I need to add the user name or some other identifier to make it unique?

 

You will have to think about where you will put it – and do you delete it afterwards (II_TEMPORARY) ?

 

A number of questions for you think about in the context of your environment, but a skeleton idea might be:

 

II_TMP = varchar(2000);

Checkw4glrun = varchar(2000) not null; // Command to run

Checkw4glrun_file = varchar(2000) not null; //Results file name

Otherw4glrun_so = StringObject; //To load the resulting file.

.

.

.

II_TMP = CurSession.Getenv(name = ‘II_TEMPORARY’ );

Checkw4glrun_file = II_TMP+’\w4gltasklist.txt’;

Checkw4glrun = ‘wmic process where "name='w4glrun.exe'" get commandline /format:list >’  + Checkw4glrun_file

 

//Stop the dreaded black box:

 

CurSession. ProcessWindow = FALSE;

Call system Checkw4glrun;

//Check the errorlevel….

If CurSession. CallSystemStatus!= 0 then….something went wrong

//Load the results

Otherw4glrun_so.Filename = Checkw4glrun_file;

 

//Delete the file? May have to use the Windows API

//Parse your stringobject using StringObject.Split() method.

//Look for others….

Adrian Williamson

unread,
Jul 8, 2022, 4:31:16 AM7/8/22
to openroa...@googlegroups.com

Hi,

 

OK it’s Friday I knocked this up and checked it compiled.

 

I still reserve the right to have got bits wrong….

 

procedure CheckForOtherw4glrun

(

 

) =

declare

 

        II_TMP = varchar(2000);

        Checkw4glrun = varchar(2000) not null; // Command to run

        Checkw4glrun_file = varchar(2000) not null; //Results file name

        Otherw4glrun_so = StringObject; //To load the resulting file.

        w4glrunprocs = array of stringobject;

        isrunning = i4 not null;

        i = i4 not null;

 

enddeclare

{

 

 

        II_TMP = CurSession.Getenv(name = 'II_TEMPORARY' );

       

        if II_TMP is null then

                //it is not defined..

                CurExec.Trace(text = 'Something went wrong II_TEMPORARY is null ' );

                exit;

        endif;

       

        Checkw4glrun_file = ifnull(II_TMP,'')+'\w4gltasklist.txt';

        Checkw4glrun = 'wmic process where "name='+HC_QUOTE+'w4glrun.exe'+HC_QUOTE +'" get commandline /format:list >'  + Checkw4glrun_file;

 

        //Stop the dreaded black box:

 

        CurSession.ProcessWindow = FALSE;

        Call system Checkw4glrun;

        //Check the errorlevel….

        If CurSession.CallSystemStatus != 0 then

                CurExec.Trace(text = 'Something went wrong errorlevel = ' + varchar(CurSession.CallSystemStatus ));

        else

                //Load the results

                Otherw4glrun_so.FileHandle = Checkw4glrun_file;

                //Parse your stringobject using StringObject.Split() method.

               

                w4glrunprocs = Otherw4glrun_so.Split(delimiter = HC_NEWLINE);

               

                isrunning = 0;

                for i= 1 to w4glrunprocs.lastrow do

                        //Look for others….

                        if w4glrunprocs[i].locateString(match = 'myapp.img') != 0 then

                                isrunning = isrunning + 1;

                        endif;

                endfor;

               

                if isrunning > 1 then

                        exit; //?

                endif;

 

                //Delete the file? May have to use the Windows API

               

        endif;

Allan Biggs

unread,
Jul 8, 2022, 6:14:47 AM7/8/22
to openroad-users
I no longer have access to the code.

The way I used to do it was a table of running users for each application. We once had a problem of users leaving the application running overnight or at least when they were away from the terminal and we wanted to update the application. Our apps sat on a common drive and update involved copying the new application over the current one. If the application is in use you can't do this.

So I set an event on a delay in a ghost frame,I think, when the application started it looked to see if it needed to close down. A bit more complex than that but I hope you get the idea.

That event on first time in, checked to see if the application was already running and if not set up the 'I am running ' entry in the table.


On a mobile big fingers so forgive the brevity and grammar...

Allan





--
Sent from my Android phone with mail.com Mail. Please excuse my brevity.

Paul White

unread,
Jul 8, 2022, 6:15:05 AM7/8/22
to openroa...@googlegroups.com

Friday yeah!

Rowell, you might like a simple blunderbuss approach which we use to address the problem where the OpenROAD process may be stuck, or minimised off the screen. This is especially useful for the mobile/handheld devices connected via Citrix.  When the forklift operator goes out of wifi range,  the connections sometimes drops but the session remains, so the forklift driver reconnects, the existing app will be terminated.  Here are some commands to demonstrate:

C:\Temp>tasklist /FI "IMAGENAME eq w4gldev.exe" 2>NUL | find /I /N "w4gldev.exe"
[4]w4gldev.exe                  76044                           13    238,752 K
[5]w4gldev.exe                  23856 ICA-CGP#19                 4    247,472 K

C:\Temp>echo %errorlevel%
0

C:\Temp>tasklist /FI "IMAGENAME eq w4gldev.exe" /FI "USERNAME eq %USERNAME%" 2>NUL | find /I /N "w4gldev.exe"

C:\Temp>echo %errorlevel%
1



And an excerpt from the application start up script

tasklist /FI "IMAGENAME eq w4glrun.exe" 2>NUL | find /I /N "w4glrun.exe">NUL
if not "%ERRORLEVEL%"=="0" goto kill w4glrun

goto startup


:kill w4glrun
taskkill /f /im w4glrun.exe

:startup

start/min %II_SYSTEM%\ingres\bin\w4glrun.exe %IMAGEPATH% -d%DB% %TRACE%

Paul
&



Bodo Bergmann

unread,
Jul 8, 2022, 6:17:02 AM7/8/22
to openroa...@googlegroups.com

Here is an example without using a temporary file.

The procedure returns an integer - TRUE if the image (specified by the imagename parameter) run by w4glrun.exe was found, FALSE otherwise.

procedure CheckRunningImage

(

       imagename = varchar(100) not null

) =

declare

       rv = INTEGER NOT NULL;

       pwait = INTEGER NOT NULL;

       pwin = INTEGER NOT NULL;

       cmd = varchar(2000) not null;

enddeclare

{

       pwait = CurSession.ProcessWait;

       pwin = CurSession.ProcessWindow;

       CurSession.ProcessWait = TRUE;

       CurSession.ProcessWindow = FALSE;

       cmd = 'cmd /c wmic process where "name=''w4glrun.exe''"  get CommandLine | findstr ' + imagename;

       CALL SYSTEM :cmd;

       IF CurSession.CallSystemStatus = 0 THEN

              rv = TRUE; // image was found

       ENDIF;

       // Restore original values

       CurSession.ProcessWait = pwait;

       CurSession.ProcessWindow = pwin;

       RETURN rv;

}

 

Cheers,

Bodo.

rowellmagno

unread,
Jul 25, 2022, 11:57:21 PM7/25/22
to OpenROAD Users Mailing List
Hi,

I thought I already replied to this thread.
The codes provided works and currently applying it to one of our projects.
Thank you very much,

Rowell
Reply all
Reply to author
Forward
0 new messages