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
16
  • 1
    Shortcut keys were always flaky. A brute-force solution would be to schedule the execution of the batch file repetitively every minute. If the programs are running, I don't suppose that this will be noticeable by the user.
    – harrymc
    Feb 12, 2016 at 19:49
  • @harrymc - I was thinking of something similar, but it might cause problems if the worker is scanning and the program looses focus. Also the workstations work a bit slow and even for a simple batch file like this it takes 5-10 seconds to run
    – Divin3
    Feb 15, 2016 at 6:30
  • 5-10 seconds just to detect that the programs are running? If you publish the batch file we might be able to improve it.
    – harrymc
    Feb 15, 2016 at 6:42
  • @harrymc - updated. It takes long because the workstations are too slow
    – Divin3
    Feb 15, 2016 at 7:13
  • I don't know what you have on these systems. WMIC might be faster : WMIC process get Caption | find /i /n "prog.exe. There is also Powershell Get-Process and also Powershell via WMI: Get-WMIObject Win32_Process.
    – harrymc
    Feb 15, 2016 at 8:39

2 Answers 2

1
+50

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 :

4
  • I will test it and give a feedback asap
    – Divin3
    Feb 16, 2016 at 9:41
  • I see this as the best solution as well. I have one problem that I have ran into. I have to make the batch file run in the background. It must not steal focus not even for a flash because it might interrupt scanning. Best solution that I have found so far was %comspec% /c start "" /min <path>\file.bat ^& exit but it is still not how it should work.
    – Divin3
    Feb 17, 2016 at 5:19
  • See this thread : Run a batch file in a completely hidden way.
    – harrymc
    Feb 17, 2016 at 6:54
  • I am a bit disappointed because there's no "Windows hack" to make the hotkeys work as the original idea but this is a great workaround. In the final conclusion I have decided to make 2 batch files in the start menu that will enable/disable the Task Scheduler and the script will be loaded from a network share. I need to add some more error handling (in case the file can not be accessed, or any problem happens), but I will be able to handle that. Thank you for your effort and the great answer.
    – Divin3
    Feb 17, 2016 at 7:35
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.

1
  • It is not safe to turn off the apps while running, it may cause even bigger problems. Also the applications do not close when alt+f4 is pressed. Application A even prompts for a password to close.
    – Divin3
    Feb 15, 2016 at 6:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .