2

At my company we have small workstations ~13 inch with touchscreen.
The operating system is: Microsoft Windows Embedded Standard 6.1.7601 Service Pack 1 Build 7601
The workstations have 5 buttons on them that can be mapped for any key combination. (example ctrl+alt+shift+[any key on the keyboard])

There are two programs that must run on them in order for the workers to be able to work. Sometimes the workers accidentally close one of the programs, so I have decided to get a solution to this, since they can not start the programs by themselves.

So I have:
- created a batch file, that when started, it checks if the programs are running, if not, it starts them;
- created a shortcut of the batch file (in %appdata%\Microsoft\Windows\Start Menu\Programs as suggested here);
- added a shortcut key (ctrl + alt + s);
- assigned one of the buttons on the workstation to the key binding.

It seemed a good idea in theory but in practice the shortcut key binding wasn't working properly.

After troubleshooting, I realized that one of the programs is causing the problem.
Lets call the programs A and B. When B or the desktop is in front, the key combination works properly and launches the batch file. A works in full screen. So when the key combination is pressed while A is in front it doesn't work.
So I have assigned an alt + tab key combination for another button but this is where the problem kicks in.

If I have previously pressed the ctrl + alt + S key combination while A was in front, it wont work afterwards even after I switched to B or to the desktop.

What makes it more interesting is, that if I create another shortcut key on another shortcut file, lets say ctrl + alt + D and run it after ctrl + alt + S stopped working, it fixes it and the ctrl + alt + S starts working again while B or the desktop has focus.

Tried this, didn't work.
Red this forum. No solution.

I am looking for a solution/workaround/another method to solve this problem.

I don't want to install any third party programs. I can however modify settings and the registry if needed.

EDIT:

The batch file

echo off
tasklist /FI "IMAGENAME eq progB.exe" 2>NUL | find /I /N "progB.exe">NUL
if "%ERRORLEVEL%"=="1" (
cd C:\<progB path>
start /MAX progB.exe

)

tasklist /FI "IMAGENAME eq progA.exe" 2>NUL | find /I /N "progA.exe">NUL
if "%ERRORLEVEL%"=="1" C:\<progA path>

exit
Lrnd
  • 1,811

2 Answers2

1

A brute-force solution is to schedule the execution of the batch file repetitively every minute. The goal is that if the programs are running, that this check will not be noticeable by the user.

Unfortunately, on these slow computers running Windows Embedded Standard 6, tasklist and its variant are much too slow, so we have to find another mechanism for checking if the programs are running. Fortunately, it seems that checking for the existence of a file is still very fast.

The mechanism I propose is to launch the programs using this syntax :

prog 2 >> \path\to\lockfile

The "2 >> file" parameter signifies that the error file of prog is redirected to lockfile. This file, also called stderr on Linux, is normally never written-to by most programs. While the program is running, the file is locked and cannot be deleted, since it is in use. If the program is stopped, the file may or not exist, but it can be deleted.

Here is an example of a script that checks whether a file exists and can be deleted. I have added echo commands, useful while debugging such a script.

@echo off
if exist \path\to\lockfile (
  echo lockfile exists
  del \path\to\lockfile
  if exist \path\to\lockfile (
    echo lockfile is locked - program is running
  ) else (
    echo lockfile was deleted - program is not running
    **launch program here**
  )
) else (
  echo lockfile doesn't exist - program is not running
  **launch program here**
)

To close the program without it starting automatically, as for maintenance, disable the scheduling of the batch file.

Or, if that's too much bother, add another file called "maintenance" and check for its existence in the batch file, doing nothing if it exists. Delete the file when the maintenance is ended.

For testing, one can lock the file via this batch script. Press any key to stop :

pause 2 >> \path\to\lockfile

References :

harrymc
  • 498,455
0

Your approach to this problem is unique, and sounds close, but it's running away from you. Thinking along the same path you've been following so far, here's an offer.

If it's safe to, which you will have to thoroughly determine, you may want to choose to use a key bind to Alt+F4 the applications. It would be even better if you could do a combination of Alt+Tab first, then Alt+F4. Theoretically, you would be able to close both applications and return to the desktop by pressing this key bind a maximum of three times.

This would leave you in a position where you know the exact state of both applications - not running. Using a redacted version of your bind, you can then launch your applications (there is no longer the need to check if they are running).

Example (both applications are running):

  • application A has window focus
  • [press bind] B has focus and closes, returning focus to A
  • [press bind] desktop has focus, and nothing closes
  • [press bind] A has focus and closes

Example 2 (B has been closed):

  • desktop has window focus
  • [press bind] A (for example) has focus and closes, returning focus to desktop

Alternatively, you could have one key to do the Alt+Tab and another key to do the Alt+F4. The users would have to press key 1, followed by key 2, for a total of 3 presses for each button.

It is up to you to determine if Alt+F4ing your applications is safe. One might consider this never to be safe, but it absolutely is not safe to do if your applications process data actively, process data based on a schedule, have an active database connection, ect. If the applications happen to only carry out their function(s) when a user intervenes with a request, and Alt+F4ing each application does not leave any unforgotten temporary data or locks, there may be no consequence.

As always, there is more than one approach to your problem. This specific solution sticks with your initial thought process and overall theme.

root
  • 3,920