Solved

Difference between *.com and *.bat under W2K

Posted on 2002-03-25
21
415 Views
Last Modified: 2010-04-14
My question is:
What is the difference between .com file and .bat file.
I mean internals, how they are executed by the kernel and differences in memory allocation etc.
0
Comment
Question by:omk
  • 9
  • 4
  • 4
  • +2
21 Comments
 
LVL 2

Author Comment

by:omk
ID: 6894889
I am intersted only in Windows 2000.
Thanks
0
 
LVL 11

Expert Comment

by:griessh
ID: 6894924
exe and com files are binaries that are loaded into memory and executed. A com file has one special feature, the executable will fit in one 64KB segment (they were created in the early DOS days when RAM was still precious ...).

A bat file is first of all a text file. This text file contains commands that could be run from a command line. Instead of doing this manually, the command interpreter will open a new shell for you and then execute the commands in the bat file. (So writing your own batch interpreter isn't too difficult, you need to read a text file that follows a few rules and then you do a ShellExec()).

And that is valid for all Windows versions.

I guess that's not enough for you (300 points?), but you will have to be a bit more specific about what you need to know.

======
Werner

0
 
LVL 16

Expert Comment

by:Kyle Schroeder
ID: 6895093
Did you maybe mean the difference between .bat and .cmd?  To the best of my knowledge, the only difference there is a .cmd is only executable under an WinNT (NT 3.x, NT 4.x, Win2K, WinXP) environment, while a .bat will run in either.  .cmd is used to designate that the file is for NT, and may contain NT specific commands.

-dog*
0
 
LVL 2

Author Comment

by:omk
ID: 6895259
I mean exactly what I mean, what is the difference between say test.bat and test.com under windows 2000.
Say I have test.bat. Then I rename it to test.com.
Then I create a shortcut to test.com. Then I rename test.com back to test.bat. Then I edit the shortcut so that it still point to this test.bat. So my question is why the system treats this test.bat different, than if I siply created a shortcut to initial test.bat.
FYI these are DIFFERENT.
0
 
LVL 16

Expert Comment

by:Kyle Schroeder
ID: 6895281
What?  First I wonder why you're spending so much time renaming bat files and editing their shortcuts...but I'm sure you must have a reason...

What do you mean that "the system treats this test.bat different"?

OK...I worked through your strange question, and I think I know what you are talking about.  When you make a shortcut to a .com file, its not just a typical .lnk file.  If you examine the shortcut, it is actually test.com.pif.  The .pif indicates that the program it is targeted at is a MS-DOS .EXE or .COM program.  Creating a shortcut to test.bat creates a file test.bat.lnk.  A .lnk (link) file is a standard Windows shortcut that can be used for any file (except the abovementioned MS-DOS .COM or .EXE file) or even a folder.  Windows processes .LNK files differently than .PIF files; if you are extremely curious as to the low-level "what's happening exactly" differences, you might want to check the Windows 2000 Resource Kit which you can purchase at most bookstores that carry computer books, or direct from Microsoft, Amazon, BN.com, etc....

-dog*
0
 
LVL 2

Author Comment

by:omk
ID: 6895294
OK,
It is very close.
say i have ResKit, can you point where I can find detailed explanation there?
0
 
LVL 2

Author Comment

by:omk
ID: 6896107
You can look thru this link with related (not the same) issue
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q139628
I really curious what happens on the lowest level as it is only possible with Microsoft products.
I am not able to give more than 300 points for a single question, but I will raise it up to a 1000 points for a complete answer.
0
 
LVL 2

Expert Comment

by:xchange
ID: 6909779
So, as werner pointed out, the system will EXECUTE a .com file. Whereas in the case of a .bat file the system will execute COMMAND.COM instead and pass it the '.bat file's name as a parameter.

 So, in BOTH cases, a .com file is run actually.
The difference is when you run it from!
a) From the desktop as an icon: The system will set-up the .com's environment accordinf to user-defined settings that can be found by rclick | properties (Memory, etc.)
b) From the Command-Line: The system will set-up the .com's environment to be similar to the Command-line's (Command.com), .com will inherit it from command.com process.

Just another litle point:
 If at the command prompt you do not specify an extension, .com files are executed in favor of .bat files.

---
Theo
0
 
LVL 2

Author Comment

by:omk
ID: 6909999
to xchange
Thanks for your comment.
Say you know that cmd and command are different?
My question is HOW it is executed.
To grasp an idea: almost everybody can drive a car,
signifficantly less can test and repair it, but there are only a few who know exactly what happens in your engine.
I seach for assistance of those few.

Thanks
0
 
LVL 11

Expert Comment

by:griessh
ID: 6910071
omk

exe and com files have a header that keeps informations about the binary (stack, memory etc).

You can always do a search in your favourite search engine for "exe header" ... here is one link I used: http://www.delorie.com/djgpp/doc/exe/

======
Werner
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 2

Author Comment

by:omk
ID: 6910211
Yes, this header is used for memory allocation.
I also have a description of undocumented pif structure.
Please read carefully my "rename" explanation of the issue,
I do not change file headers.
dogztar explained very well the visible difference between pif and lnk.
The results that I have with this "renaming" are so exiting, that I decided to find out the internals.
I need the level of explanation similar to "Inside Microsoft Windows 2000"

Thanks a lot
 
0
 
LVL 11

Expert Comment

by:griessh
ID: 6910256
omk

I am really not sure what you try to accomplish. Could you give us some idea WHAT you want to do by renaming .bat to .com and back and forth?

======
Werner
0
 
LVL 2

Author Comment

by:omk
ID: 6910771
I already have the result. But I need to understand what actually happens. With this funny renaming you can receive access to a very protected system resources.
0
 
LVL 2

Expert Comment

by:xchange
ID: 6912249
dog, are you sure that you get a .lnk for .bat files?
I have WinME :(, but when I create shortcuts for .com and .bat files, .pif files are created in both cases!
 Can someone with Win2k actually verify this? And also verify if Win2k  uses command.com or cmd.exe(?) for executing .bat files?

omk> I already have the result.
What result?
0
 
LVL 2

Author Comment

by:omk
ID: 6912874
to xchange
I have mentioned that I am interested in windows 2000 ONLY,
not in DOS systems as Win ME.

Thanks
0
 
LVL 11

Expert Comment

by:griessh
ID: 6914084
omk

>>DOS systems as Win ME
That is an insult for DOS!

======
Werner
0
 
LVL 2

Expert Comment

by:xchange
ID: 6917844
...moreover: WinME is not a DOS system (at least not more than W2k).
Probably you COULD say that for Win_3x and Win9x series but not for WinMe.

Anytime.
0
 
LVL 16

Expert Comment

by:Kyle Schroeder
ID: 6918620
Really...hmm.  I'm very sure that WinME still has a lot of nasty 16bit code deep in its kernel and core files...They would like you to believe its all 32bit, but its just not true.
0
 
LVL 11

Expert Comment

by:ewtaylor
ID: 8905489
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
[split dogztar griessh xchange]
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
[ewtaylor]
EE Cleanup Volunteer
0
 
LVL 16

Accepted Solution

by:
Kyle Schroeder earned 300 total points
ID: 8905822
Also...WinME is *PART* of the Win9x series...
0
 
LVL 2

Author Comment

by:omk
ID: 8909794
I like dogztar approach. I give him points because he tried.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
This video discusses moving either the default database or any database to a new volume.
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: …

746 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

12 Experts available now in Live!

Get 1:1 Help Now