What is the difference between CMD and BAT file ?

J

John

Hi,

Could anyone give me some advice on when to use CMD and BAT file ?

This is because we are going to run some scripts to delete the shortcuts in
desktop. We already got the command but some fellow says it should be with
BAT extension and some with CMD one.

Your advice is sought.

John
 
W

Wesley Vogel

..cmd files will NOT work on non NT Windows versions where .bat files will.

Both .cmd and .bat files work on NT Windows versions.

Windows XP is really Windows NT 5.1.

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
W

Wesley Vogel

Forgot this.

..CMD will be listed in PATHEXT under Set in NT in a command prompt and will
NOT be listed under non NT i.e. Windows 9x, Me, etc.

The environmental variable PATHEXT shows a list of file extensions that are
considered to be executable and regulates which extensions do not need to be
typed in a Command Prompt or the Run command.

---------------------------
Report Class Name
---------------------------
File Extension .cmd
File Class cmdfile
File Description Windows NT Command Script

Files of .cmd will be listed in the File Types dialog box as Windows NT
Command Script.
---------------------------

Report Class Name
---------------------------
File Extension .bat
File Class batfile
File Description MS-DOS Batch File

Files of .bat will be listed in the File Types dialog box as MS-DOS Batch
File.
---------------------------

There is a difference in NT on how .cmd and .bat files are handled.

<quote>
The differences between .CMD and .BAT as far as CMD.EXE is concerned are:

With extensions enabled, PATH/APPEND/PROMPT/SET/ASSOC in .CMD
files will set ERRORLEVEL regardless of error. .BAT sets ERRORLEVEL
only on errors.

Mark Zbikowski \(MSFT\)
<quote>
from...
http://groups.google.com/group/microsoft.public.win2000.cmdprompt.admin/msg/ad9066638815812c


--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
J

John

Dear Wesley,

Thank you for your advice.

From your message, my understanding is that BAT can be applied to both NT
and non-NT workstations (We only have XP & a couple W2K workstations). And
BAT will not cause error message for commands like
PATH/APPEND/PROMPT/SET/ASSOC. I would like to know why do we use CMD then.

John
 
T

Tim Slattery

John said:
Hi,

Could anyone give me some advice on when to use CMD and BAT file ?

This is because we are going to run some scripts to delete the shortcuts in
desktop. We already got the command but some fellow says it should be with
BAT extension and some with CMD one.

From what I can tell, *.cmd and *.bat files are processed exactly the
same way in WinXP. But XP has command-line commands that are not
available in earlier environments (especially the Win9x line of
operating systems). Using the *.cmd extension makes it explicit that
this procedure was written for XP, or at least for the NT line (WinNT,
Win2000, WinXP) and probably needs to be looked at before being run on
a Win9x system.
 
W

Wesley Vogel

It is my understanding that .cmd file will NOT run on a Win9x system. The
extension can be changed to .bat and depending on what's in the file, they
might run.

I do not have anything but this machine with XP on it so I cannot check this
out first hand. I have to take it on faith, like so many things. ;-(

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
W

Wesley Vogel

If you only have XP & W2K I, personally see no reason why you cannot use
either or both.

Use both and keep all of your people happy. ;-) Or unhappy as the case may
be.

It would really depend on what your using the files for and how complicated
they are.

The only .bat and .cmd files that I use are really simple; start, del, rd,
cd. Nothing fancy. And it makes no difference on my simple files.

I have two .cmd files that are part of XP.

%SystemRoot%\System32\Login.cmd for Telnet Server.
and
%SystemRoot%\System32\usrlogon.cmd for Terminal Server.

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
T

Tim Slattery

Wesley Vogel said:
It is my understanding that .cmd file will NOT run on a Win9x system.

Right, the OS wouldn't know what the *.cmd extension was.
The extension can be changed to .bat and depending on what's in the file, they
might run.

Right again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top