Sunday, February 15, 2015

Shortcut file not always starting when shortcut key is pressed


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:\
start /MAX progB.exe
)
tasklist /FI "IMAGENAME eq progA.exe" 2>NUL | find /I /N "progA.exe">NUL
if "%ERRORLEVEL%"=="1" C:\
exit

Answer



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 :


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...