Timing conflict in a batch file in x32Win10ProV22H2

Solved
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 - Apr 20, 2024 at 06:51 AM
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 - May 2, 2024 at 06:05 AM

I will present two versions of a batch file, and list the effects they have.

Start "" "C:\Program Files\ToggleTaskbarAutohide\ToggleTaskbarAutohide.exe"
timeout 1
Start "" "C:\Program Files\Macro Express Pro 6\MeProc.exe" /ASaveDeskTopView
timeout 1
Start "" "C:\Program Files\ToggleTaskbarAutohide\ToggleTaskbarAutohide.exe"

The third 'START' line takes effect before the second one has completed  
 

Start "" "C:\Program Files\ToggleTaskbarAutohide\ToggleTaskbarAutohide.exe"
timeout 1
Start "" "C:\Program Files\Macro Express Pro 6\MeProc.exe" /ASaveDeskTopView
timeout 2
Start "" "C:\Program Files\ToggleTaskbarAutohide\ToggleTaskbarAutohide.exe"

When the second timeout is increased to anything over '1', the CMD window for the third START line is superimposed on the snip image (thus spoiling it).

How to get the third command to 'wait' till the second has completed ?
 

Related:

11 responses

Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 3
Apr 21, 2024 at 08:10 AM

The AI suggestion of using 'wait' has the weakness that although the execution of the the third command is delayed, what was NOT delayed was the appearance of the CMD window which processes that wait command. Rhat appearance spoils the snip.

0
HelpiOS Posts 14517 Registration date Friday October 30, 2015 Status Moderator Last seen November 19, 2024 1,865
Apr 22, 2024 at 10:39 AM

Hi,

Try replacing "start" by "call":

call "C:\Program Files\ToggleTaskbarAutohide\ToggleTaskbarAutohide.exe"
call "C:\Program Files\Macro Express Pro 6\MeProc.exe" /ASaveDeskTopView
call "C:\Program Files\ToggleTaskbarAutohide\ToggleTaskbarAutohide.exe"

"Call" will process all commands within the same command prompt window. It will also wait for each command to complete before starting the next one.

Let me know how it goes.


0
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 3
Apr 22, 2024 at 08:58 PM

There is NO CMD window superimposed on the snip, but the third command took effect before the second completed.

0
HelpiOS Posts 14517 Registration date Friday October 30, 2015 Status Moderator Last seen November 19, 2024 1,865
Apr 23, 2024 at 11:18 AM

Here's a workaround - add this line before the third command:

timeout /t 5 /nobreak

Execution of the last command will be delayed by 5 seconds. "nobreak" will prevent the command to be executed if a key is pressed.

You can adjust the timeout if necessary.


0
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 3
Apr 23, 2024 at 02:45 PM

As I expected, the time-out line triggers a CMD window which superimposes itself over the image i want  a snip of.

0
HelpiOS Posts 14517 Registration date Friday October 30, 2015 Status Moderator Last seen November 19, 2024 1,865 > Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024
Apr 23, 2024 at 04:10 PM

What if you try this one instead?

timeout /t 5 /nobreak>nul

If that persists, try adding @echo off at the beginning of your batch file. Otherwise, you could remove that third line and create instead a shortcut on your desktop in order to unhide your taskbar.

0
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 3
Apr 23, 2024 at 08:42 PM

'you could remove that third line and create instead a shortcut on your desktop in order to unhide your taskbar.'

Obviously I can - and have - until such time as I can get the batch file to work better.

You latest version still has the CMD window intruding on the image.

The latest

0

Didn't find the answer you are looking for?

Ask a question
HelpiOS Posts 14517 Registration date Friday October 30, 2015 Status Moderator Last seen November 19, 2024 1,865
Updated on Apr 26, 2024 at 02:40 PM

I've another method you could try in order to prevent the batch file from appearing on the screen. You'll need to create a task in Task Scheduler and create a shortcut on your desktop to be able to start that task.

First of all, update your batch file with the latest changes:

@echo off
call "C:\Program Files\ToggleTaskbarAutohide\ToggleTaskbarAutohide.exe"
call "C:\Program Files\Macro Express Pro 6\MeProc.exe" /ASaveDeskTopView
timeout /t 5 /nobreak>nul
call "C:\Program Files\ToggleTaskbarAutohide\ToggleTaskbarAutohide.exe"
exit

Next, go to Task Scheduler. Right-click Task Scheduler Library and select Create Task. Give a name to your task (you'll need it later) then go to Actions > New.

Enter the following and save the task:

  • Action: Start a program
  • Program/script: %windir%\system32\cmd.exe
  • Arguments: /C start /min C:\Users\YourName\Desktop\batch.bat

Don't forget to change the path pointing to your batch file.

Once the task is saved, go back to your desktop. Do a right-click to open the contextual menu and choose New > Shortcut, then enter:

schtasks /run /tn "TaskName"

TaskName corresponds to the name provided to your task in Task Scheduler.

Save the shortcut and you can test it. With this method, your batch file should run minimized - it won't appear on the screen.

I hope that will work as expected.

Good luck


0
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 3
Apr 25, 2024 at 05:22 AM

Sad to report, the process opens a CMD window and halts at

C:\WINDOWS\system32 >

0
HelpiOS Posts 14517 Registration date Friday October 30, 2015 Status Moderator Last seen November 19, 2024 1,865 > Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024
Apr 26, 2024 at 02:40 PM

I've discovered a mistake, your batch file in "Add arguments" for the task must ends with .bat - I've corrected my previous answer. Check again the parameters to make sure everything is correct. Also, if your task or batch file has spaces in their filenames, try removing them to prevent potential issues.

0
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 3
Updated on Apr 29, 2024 at 02:41 PM

It is obvious that a batch file must end in '.bat'.  Are you saying that you have corrected post #8, and I should now try it as it currently appears ?

On the assumption that the answer is YES,  I tried it - and it succeeds ! Thank you SO MUCH !

0
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 3
Updated on Apr 29, 2024 at 02:40 PM

When I related my experience, as shown in the image, in this space, I could not submit it because of "Please enable Javascript. Please try again." which I do not know how to comply with, so I will send you an image of what I had written.

In the screenshot above, the '\/' instead of 'v' is an artifact of text-capture, and does NOT reflect the actual 'details' in Task Scheduler.

I have done it again - in my 'continuing system' - to the best of my knowledge just as above, without any renaming or relocating, and what happens is that a CMD window opens minimized, and stalls at ‘C : \WINDOWS\system32>

0
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 3
Apr 29, 2024 at 12:59 AM

I got it to work in my continuing system - using my own version of the batch file, with an increased first timeout.

0
HelpiOS Posts 14517 Registration date Friday October 30, 2015 Status Moderator Last seen November 19, 2024 1,865
Apr 29, 2024 at 02:39 PM

Great! Thanks for the update.

0
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 3
Apr 29, 2024 at 06:58 PM

Things keep changing ! Trial and error seemed to show that the first timeout had to increase, but it was not consistent, and has worked with both timeouts being just 1.

Functionality depended heavily on the path to the batch file - and I arranged for it to be C:\batch file, rather that the location where I prefer my batch files to be.  Thank you once again.

0
ZehraB Posts 3 Registration date Thursday May 2, 2024 Status Member Last seen June 7, 2024
May 2, 2024 at 01:08 AM

To ensure the third command waits until the second has fully completed, replace start with start /wait for the second command to make the batch process wait for the application to finish before proceeding to the next command.

0
Sebastian42 Posts 63 Registration date Tuesday March 30, 2010 Status Member Last seen May 2, 2024 3
May 2, 2024 at 06:05 AM

ZehraB

I have worked on this a long time - and have achieved success, so no more tweaking is needed.

Along the line I did use 'start/wait' and it did NOT have the desired effect.

I might add that there was inconsistency in the timeouts - working and NOT working for the same amounts.

0