Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

bat-file - load programs in certain order

Apr 1, 2012 9:52PM PDT

Hello,

I have nearly 10 programs, which MUST to be loaded in a certain order - like p1,p2,p3,p4,p5,p6,p7,p8,p9,p10.
I want to add them to a .bat-file.
Need to ensure that loading of p2 will start only after p1 is loaded, and so on.
- Does anybody know how to do that?

Thanks!

Discussion is locked

- Collapse -
Answer
It's been a while
Apr 1, 2012 11:24PM PDT

It's been a while, but there should be some kind of a command that causes the interpreter to wait for one process to finish before moving onto the next. Why not hit Google or Microsoft's TechNet site probably has a full rundown on batch file scripting. Though it's entirely possible that sort of thing is beyond the scope of batch scripting and you'll need to take a step up to the likes of PowerShell or one of the three primary scripting languages: Perl, Python, or Ruby.

Not sure about PowerShell, but I know the latter trio can be compiled into an executable so you don't necessarily need the interpreter installed on that machine. You don't gain any performance by doing that, but then performance really isn't your goal.

- Collapse -
Answer
Also been a while but a suggestion
Apr 1, 2012 11:56PM PDT

Writing the individual lines should be no problem but I'd suggest some sort of batch file compiler would be helpful so that you could easily run it from the startup folder. I believe there are free batch file compilers out there. Just a thought.

- Collapse -
Answer
So why not the START command in batch?
Apr 2, 2012 3:19AM PDT

You have the START common and its switches. You can also use the CHOICE command and its /T (timeout) to add delays if need be.

You didn't reveal why you didn't get this done.
Bob

- Collapse -
Reply
Apr 2, 2012 7:56AM PDT

I need to achieve the following - programs' icons in the taskbar (the bar at the bottom of the screen) must be in the order I define in the bat-file.
The problem is that the load-time of each program is different (depends on internal variables of each program), so the second program's GUI might appear before the first and the order will be "destroyed".
Therefore, before running the second need to verify somehow that the first is successfully loaded.

Thanks!

- Collapse -
That's why you have CHOICE and its timeout to tinker with
Apr 2, 2012 8:05AM PDT

And if you ever make it over to Windows 7, you can click and drag the icons in the area you want to the order you want and I think I see them maintain the order I moved them to!

The problem you noted is not much of a problem. You only need to change the timeout of the Choice to match the longest time it takes.

We can get better results with writing our own launcher apps and looking at the notification tray to see when the app shows up but then you might be running out of time to get this working?
Bob

- Collapse -
Reply
Apr 2, 2012 10:47AM PDT

Hello Bob,

I need to clarify the following line:
"You only need to change the timeout of the Choice to match the longest time it takes".

The longest time depends on internal variables of programs and it is not constant.
Usually it is 10-20 seconds, but sometimes it might take several minutes.
If I will add 2-3 min per program then the whole process will take too much time and it will not be acceptable.

This issue is not very urgent and I thought that maybe there is a simple solution.
But if not I will use my current workaround - I added "pause" after each line,
so I manually confirm ("press any key") when it is OK to start to load next program.
Using this way I already avoided repetitions of clicking icons and waiting (10 times).


Thank you!

- Collapse -
It can be coded up.
Apr 2, 2012 11:08AM PDT

By using a custom launcher that does more than just wait. We could monitor the notification tray for the app to show up as well as watch the tasks for their CPU use to come back down.

All this is possible. Here we can't go that deep since most are strained at the simplest of batch files. So there it is, all possible.
Bob

- Collapse -
Second thought. Why are you booting up at all?
Apr 2, 2012 11:09AM PDT

Here my old XP is using hibernation and boots about once every other month. It seems like you could avoid this issue with a simple change to use HIBERNATION.
Bob

- Collapse -
Third thought. Link.
Apr 3, 2012 7:15AM PDT
http://support.microsoft.com/kb/945011

"Note You can determine whether these service initializations are finished by observing the hard disk light activity (if your computer has this feature). If the hard disk drive light blinks intermittently instead of being solidly lit, these service initializations might be finished. You can also check CPU usage on the Performance tab in Windows Task Manager. If CPU usage is less than 15 percent, the service initializations are probably completed,"

I looked into the Windows API and sure enough there is no API handy to list what's in the tray for XP.
Bob
- Collapse -
Then make use of the ...
Apr 6, 2012 4:52PM PDT

multiple commands with conditional processing symbols in the batch file.

The double ampersand &&
EXAMPLE -- command1 && command2

FUNCTION -- Used to run the command following && only if the command preceding the symbol is successful. Cmd.exe runs the first command, and then runs the second command only if the first command completed successfully.

This link might help you:
http://technet.microsoft.com/en-us/library/bb490954.aspx

- Collapse -
The problem is your definition of loaded.
Apr 3, 2012 7:05AM PDT

The common definition is a program is loaded as soon as it starts doing it first instruction.
Your definition seems to be it is loaded if it's icon is on the task bar or if the GUI is shown (those are different points in time).

You would need to write a program that uses some call to some Windows internal API to find out what icons (or how many) there are in the task bar. I couldn't tell you how to do that, alas.

Kees