Solved

Run programs with batch files in Windows XP.

Posted on 2004-04-04
20
13,865 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:jimwheel
  • 8
  • 8
  • 4
20 Comments
 
LVL 67

Expert Comment

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

~sirbounty
0
 

Author Comment

by:jimwheel
ID: 10752836
Thanks ~sirbounty,

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

Any other suggestions?

jimwheel
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10752842
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.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10752866
You might also try the /Seperate switch if any of these are 16-bit...(i recongnize 2 and don't think they are...)
0
 
LVL 10

Accepted Solution

by:
timothyfryer earned 250 total points
ID: 10752934
You need to put quotation marks around anything with a space in it - so
program files should be "program files" and the whole path would be

start c:\"program files"\AnalogX\CookieWall\cookie.exe /wait

CUT AND PASTE THE FOLLOWING

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



0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10752943
Actually, just placing start /w in front of what the author posted will work, as it's already enclosed inside quotations...
0
 

Author Comment

by:jimwheel
ID: 10752985
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
0
 
LVL 10

Expert Comment

by:timothyfryer
ID: 10752990
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)



0
 
LVL 10

Expert Comment

by:timothyfryer
ID: 10753026
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
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10753033
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"
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Author Comment

by:jimwheel
ID: 10753073
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
0
 
LVL 10

Expert Comment

by:timothyfryer
ID: 10753082
I have to run for  a few but I'll test further your last code sirbounty-bback 20
0
 
LVL 10

Expert Comment

by:timothyfryer
ID: 10753464
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
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10753525
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..
0
 
LVL 10

Expert Comment

by:timothyfryer
ID: 10753559
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.


0
 
LVL 10

Expert Comment

by:timothyfryer
ID: 10753573
Thanks for pskill (pstools), have downloaded before but forgot about it until you mentioned.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10753582
LOVE Pstools...use them all the time... ;)
0
 

Author Comment

by:jimwheel
ID: 10759301
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
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10761309
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.
0
 
LVL 10

Expert Comment

by:timothyfryer
ID: 10761993
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.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Disclosure: Use this tutorial only when no other options helps to get Windows XP running without any problems and you don't want to format the drive. The back up of the data is the responsible of the user, however there is a description of how t…
If you build your web application in Visual Studio you'll get at least a few binaries, or .DLL, files in your bin folder. However, there is more compiling to be done. Normally this would happen when an ASP.NET resource within the web site is request…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now