Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

Difference between *.com and *.bat under W2K

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
omk
Asked:
omk
  • 9
  • 4
  • 4
  • +2
1 Solution
 
omkAuthor Commented:
I am intersted only in Windows 2000.
Thanks
0
 
griesshCommented:
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
 
Kyle SchroederEndpoint EngineerCommented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
omkAuthor Commented:
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
 
Kyle SchroederEndpoint EngineerCommented:
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
 
omkAuthor Commented:
OK,
It is very close.
say i have ResKit, can you point where I can find detailed explanation there?
0
 
omkAuthor Commented:
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
 
xchangeCommented:
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
 
omkAuthor Commented:
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
 
griesshCommented:
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
 
omkAuthor Commented:
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
 
griesshCommented:
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
 
omkAuthor Commented:
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
 
xchangeCommented:
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
 
omkAuthor Commented:
to xchange
I have mentioned that I am interested in windows 2000 ONLY,
not in DOS systems as Win ME.

Thanks
0
 
griesshCommented:
omk

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

======
Werner
0
 
xchangeCommented:
...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
 
Kyle SchroederEndpoint EngineerCommented:
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
 
ewtaylorCommented:
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
 
Kyle SchroederEndpoint EngineerCommented:
Also...WinME is *PART* of the Win9x series...
0
 
omkAuthor Commented:
I like dogztar approach. I give him points because he tried.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now