Link to home
Start Free TrialLog in
Avatar of jimwheel
jimwheel

asked on

Run programs with batch files in Windows XP.

I have a batch file that runs 4 programs in Win 98.  When I try to run it on Win XP, the program locks up. The code is as follows:

"D:\Program Files\AnalogX\CookieWall\cookie.exe"
"D:\Program Files\Zone Labs\ZoneAlarm\zapro.exe"
"D:\Program Files\Browser Hijack Blaster\bhblaster.exe"
"D:\Program Files\WebRunner Accelerator\webrunner.exe"

Any sugestions would be appreciated.

Jim
Avatar of sirbounty
sirbounty
Flag of United States of America image

Hi jimwheel,
Try altering the batch file - precede each line with
Start "D:\Program Files....
^^^^^

~sirbounty
Avatar of jimwheel
jimwheel

ASKER

Thanks ~sirbounty,

Tried altering the batch file - precede each line with
Start "D:\Program Files....
^^^^^
Did not work.

Any other suggestions?

jimwheel
Try Start /W
(wait for program execution to complete..)

START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/WAIT] [/B] [command/program]
      [parameters]

    "title"     Title to display in  window title bar.
    path        Starting directory
    B           Start application without creating a new window. The
                application has ^C handling ignored. Unless the application
                enables ^C processing, ^Break is the only way to interrupt
                the application
    I           The new environment will be the original environment passed
                to the cmd.exe and not the current environment.
    MIN         Start window minimized
    MAX         Start window maximized
    SEPARATE    Start 16-bit Windows program in separate memory space
    SHARED      Start 16-bit Windows program in shared memory space
    LOW         Start application in the IDLE priority class
    NORMAL      Start application in the NORMAL priority class
    HIGH        Start application in the HIGH priority class
    REALTIME    Start application in the REALTIME priority class
    ABOVENORMAL Start application in the ABOVENORMAL priority class
    BELOWNORMAL Start application in the BELOWNORMAL priority class
    WAIT        Start application and wait for it to terminate
    command/program
                If it is an internal cmd command or a batch file then
                the command processor is run with the /K switch to cmd.exe.
                This means that the window will remain after the command
                has been run.

                If it is not an internal cmd command or batch file then
                it is a program and will run as either a windowed application
                or a console application.

    parameters  These are the parameters passed to the command/program


If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:

non-executable files may be invoked through their file association just
    by typing the name of the file as a command.  (e.g.  WORD.DOC would
    launch the application associated with the .DOC file extension).
    See the ASSOC and FTYPE commands for how to create these
    associations from within a command script.

When executing an application that is a 32-bit GUI application, CMD.EXE
    does not wait for the application to terminate before returning to
    the command prompt.  This new behavior does NOT occur if executing
    within a command script.

When executing a command line whose first token is the string "CMD "
    without an extension or path qualifier, then "CMD" is replaced with
    the value of the COMSPEC variable.  This prevents picking up CMD.EXE
    from the current directory.

When executing a command line whose first token does NOT contain an
    extension, then CMD.EXE uses the value of the PATHEXT
    environment variable to determine which extensions to look for
    and in what order.  The default value for the PATHEXT variable
    is:

        .COM;.EXE;.BAT;.CMD

    Notice the syntax is the same as the PATH variable, with
    semicolons separating the different elements.

When searching for an executable, if there is no match on any extension,
then looks to see if the name matches a directory name.  If it does, the
START command launches the Explorer on that path.  If done from the
command line, it is the equivalent to doing a CD /D to that path.
You might also try the /Seperate switch if any of these are 16-bit...(i recongnize 2 and don't think they are...)
ASKER CERTIFIED SOLUTION
Avatar of timothyfryer
timothyfryer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually, just placing start /w in front of what the author posted will work, as it's already enclosed inside quotations...
Thanks  sirbounty &  timothyfryer

I CUT AND PASTED THE FOLLOWING and it worked.

start D:\"Program Files"\AnalogX\CookieWall\cookie.exe /wait
start D:\"Program Files"\"Zone Labs"\ZoneAlarm\zapro.exe /wait
start D:\"Program Files"\"Browser Hijack Blaster"\bhblaster.exe /wait
start D:\"Program Files"\"WebRunner Accelerator"\webrunner.exe /wait
 
Know I don't know who to give credit to.

jimwheel
Beg to differ sirbounty

start D:\"Program Files"\AnalogX\CookieWall\cookie.exe /wait

not the same as

"start D:\Program Files\AnalogX\CookieWall\cookie.exe /wait"

this is one of the main differences between standard dos batch convention and xp command line convention - the spaces in the file path must be enclosed in quotes in xp from what I've seen

I tested both and only the first runs on my machine (subbing calc.exe for the programs)



jimwheel - the code changed when xp came out - sirbounty code is normal dos batch code - my code is xp command line adapted - sirbounty's works on everything up to xp - mine works on xp only I think, though not tested - microsoft changed it all up for xp - yet another microsoft challenge to a universal stable programming environment
I never referenced
"start D:\Program Files\AnalogX\CookieWall\cookie.exe /wait"

I said it would with start /w in front of what the author posted, which was
"D:\Program Files\AnalogX\CookieWall\cookie.exe"

resulting in

start /w "D:\Program Files\AnalogX\CookieWall\cookie.exe"
Thanks  sirbounty &  timothyfryer

I used  timothyfryer CUT AND PASTE example so I will accept his answer.
I hope this is correct.
My next question will be, now that I used a batch file to run these programs can I use a batch file to stop them.

jimwheel
I have to run for  a few but I'll test further your last code sirbounty-bback 20
I'm not an expert on batch files but you can kill a program several different ways from script.  To kill a program from a batch file, you can invoke the tskill.exe utility in windows\system32 folder

To see the command switches available open the command window from start accessories cmd
then type       tskill

The tskill command is typically followed by the process id number of the program you want to kill, which can be found in the task manager when the program is running.  You may have to go to the View menu in Task Manager and add the Process ID column in order to see the ID number.

To test these quickly, you can copy the calc.exe file from windows\system32 and place it in your C:\ or D:\ drive.  That way you don't have to write a very long path when your experimenting with batch files.  Once you get it debugged, you can change the path up to whatever you want, just remember to enclose folder names with spaces in them with quotes like    program files    should be   "program files"
(still trying to test sirbounty method-not sure yet-not a great batch programmer here)

SO:
lets say you want to run calc.exe, a copy of which resides in the program files folder
To run it the batch file would be

start c:\"program files"\calc.exe


To kill it, you would have to open task manager while calc is running and get the process id number, lets say the pid is 1220

The command would be

tskill 1220

There are numerous ways to kill a program that don't depend upon the process id but I'm not sure whether a batch file can do it or not.  If your trying to automate the kill process, you may have to use another language like wsh - you could kill a program that you are in via using a sendkeys script in wsh

One other important note on batch files-when you run the batch file-if you create a shortcut to that batch file and then change the properties of the shortcut to run minimized, then run the batch file from the shortcut, you won't get the big command window opening up on the screen like you do when you run a batch file directly.

Post questions and I'll respond.  Here's a link to a batch and scripting guide.

http://www.robvanderwoude.com/index.html
Download PSKILL : http://www.sysinternals.com/ntw2k/freeware/pskill.shtml

You won't need a PID (process identification) number...

Just place a

PSKILL CALC.EXE
to kill the application..
sirbounty  -  I was getting two command windows, one with terminate batch job (y/n)? prompt  and another with the command prompt at desktop (where batch file was located on my machine) when I ran

start /w "c:\Program Files\calc.exe"

calc.exe didn't execute though

I thought maybe difference due to diff in compatibility modes between our machines, but I just checked cmd.exe and it said that compatibility mode could not be changed - another windows MTM (mystery to me), ha ha.


Thanks for pskill (pstools), have downloaded before but forgot about it until you mentioned.
LOVE Pstools...use them all the time... ;)
To: sirbounty & timothyfryer

Tried tskill, did not work for me.

Downloaded and tried PSKILL:
Killed three of the running programs but got an error on one.
Unable to kill process zapro.exe:
Access is denied.

I will post a question about this. If one of you would respond I can accept an answer from each of you. Only way I know how to award both as you both helped.

Thanks jimwheel
Just fyi - there's a Split Points link above your comment box in an unaccepted question... you can use that to grant assist points to multiple experts.
Thanx.
Sorry I haven't gotten back.  If you want to reallocate points from your previous accept thats ok with me.  Sirbounty contributed as much or more than I.  However you want to do it is ok by me.  As far as the tskill problem, you need to make sure that tskill.exe file is located inside your c:\windows\system32 folder which is the native path for the batch commands.  If it's not in that folder, then the batch process won't be able to execute it.
Good Luck.