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
Divin3
  • 1,775
  • 1
  • 14
  • 30
  • 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 '16 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 '16 at 06: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 '16 at 06:42
  • @harrymc - updated. It takes long because the workstations are too slow – Divin3 Feb 15 '16 at 07: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 '16 at 08:39
  • @harrymc - the stations have Intel atom processors @ 1.6 Ghz, 2Gb ram, 32 GB SSD. The processor is just enough to run the necessary programs. Even opening an explorer window sometimes seems like an eternity on these systems. Checked WMIC, it is a much more elegant solution but seems to have the same speed or even slower – Divin3 Feb 15 '16 at 08:53
  • Questions: (1) Are progA/B modifiable par yourself? (2) Can you introduce new programs? (3) If not, is it for security reasons and is a new program compiled by yourself acceptable? (4) If you open cmd and do "dir /path/to//file" is the dir also slow? – harrymc Feb 15 '16 at 09:31
  • @harrymc - 1. both programs have an ini file that can be modified. I did not find anything in them that can be useful. 2. I can but I do not want to because I can get in trouble in case the mother company finds it "unsafe". 3. Simple reg/batch files are accepted until I can give an explanation to my boss in case I am asked. There have been cases when I have introduced simple portable exe files but only when a solution was requested on a problem and it was the only possible way of solving it. 4. To give you an idea, `dir` in system32 on the workstation takes ~20 seconds for 2470 files – Divin3 Feb 15 '16 at 09:45
  • That doesn't leave too many possibilities for faster detection. Do progA/B lock exclusively any file? – harrymc Feb 15 '16 at 13:40
  • Or can you call progA/B this way : "prog 2>> file". This will lock the file exclusively, so your script can start prog if the file doesn't exist or if it's possible to delete it. – harrymc Feb 15 '16 at 16:22
  • @harrymc - I do not understand this method. Could you clarify it? – Divin3 Feb 16 '16 at 05:59
  • "prog 2>> file" launches the prog with redirection of the error file, also called stderr on Linux, on which normally nothing is written by most programs. While the program is running, the file is locked and cannot be deleted, since it is in use. If you can add "2>> file" to the program call, let me know and I will test it and add an answer detailing the method. See [I/O Redirection and Pipes](http://sourcedaddy.com/windows-7/io-redirection-and-pipes.html). – harrymc Feb 16 '16 at 07:52
  • @harrymc - yes it works, the file is created and is locked. Note that I will also need a method to be able to close the program without it starting automatically in case of maintenance. – Divin3 Feb 16 '16 at 08:43
  • I have added my answer. – harrymc Feb 16 '16 at 09:37
  • Just a quick hint - did you give the tool "AutoHotkey" a try? I've read cases where it could catch keys pressed which were not processed by the Windows Hotkey function. It's a little more complex solution, but you might give it a shot. – xpac Feb 16 '16 at 09:55
  • @xpac - I can not install third party programs because it is against the companies policy. – Divin3 Feb 16 '16 at 10:09

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
  • 455,459
  • 31
  • 526
  • 924
  • I will test it and give a feedback asap – Divin3 Feb 16 '16 at 09: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 \file.bat ^& exit` but it is still not how it should work. – Divin3 Feb 17 '16 at 05:19
  • See this thread : [Run a batch file in a completely hidden way](http://superuser.com/questions/62525/run-a-batch-file-in-a-completely-hidden-way/62646#62646). – harrymc Feb 17 '16 at 06: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 '16 at 07: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.

root
  • 3,672
  • 7
  • 27
  • 45
  • 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 '16 at 06:34