List all "Command Line" System Files - Compare to my list

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
thr333
Posts: 16
Joined: 24 Aug 2009 10:24

List all "Command Line" System Files - Compare to my list

#1 Post by thr333 » 25 Jan 2010 16:25

Hi guys,

Somebody got me thinking the other day...
He could not run some simple DOS batch files on his XP system,
further questioning revealed he was running a customized bare bones XP.
Anyhow, that leads me to my enquiry...

I'd like to run a batch file which will do the following:

Search these directories:

Code: Select all

%systemroot%\system32
%systemroot%\system32\wbem


for all the files in this list (the standard XP command line tools):

Code: Select all

arp.exe
assoc.exe
at.exe
atmadm.exe
attrib.exe
bootcfg.exe
break.exe
cacls.exe
call.exe
change.exe
chcp.exe
chdir.exe
chkdsk.exe
chkntfs.exe
cipher.exe
cls.exe
cmd.exe
cmstp.exe
color.exe
command.exe
comp.exe
compact.exe
convert.exe
copy.exe
cprofile.exe
date.exe
defrag.exe
del.exe
dir.exe
diskcomp.exe
diskcopy.exe
diskpart.exe
doskey.exe
driverquery.exe
echo.exe
endlocal.exe
eventcreate.exe
eventquery.exe
eventtriggers.exe
evntcmd.exe
exit.exe
expand.exe
fastopen.exe
fc.exe
find.exe
findstr.exe
finger.exe
flattemp.exe
for.exe
format.exe
fsutil.exe
ftp.exe
ftype.exe
getmac.exe
goto.exe
gpresult.exe
gpupdate.exe
graftabl.exe
help.exe
helpctr.exe
hostname.exe
if.exe
ipconfig.exe
ipseccmd.exe
ipxroute.exe
irftp.exe
label.exe
lodctr.exe
logman.exe
lpq.exe
lpr.exe
macfile.exe
mkdir.exe
mmc.exe
mode.exe
more.exe
mountvol.exe
move.exe
msiexec.exe
msinfo32.exe
nbtstat.exe
net.exe
netsh .exe
netstat.exe
nslookup.exe
ntbackup.exe
ntsd.exe
openfiles.exe
pagefileconfig.vbs
path.exe
pathping.exe
pause.exe
pbadmin.exe
pentnt.exe
perfmon.exe
ping.exe
popd.exe
print.exe
prncnfg.exe
prndrvr.exe
prnjobs.exe
prnmngr.exe
prnport.exe
prnqctl.exe
prompt.exe
query.exe
rasdial.exe
rcp.exe
recover.exe
reg.exe
regsvr32.exe
relog.exe
rem.exe
rename.exe
replace.exe
reset session.exe
rexec.exe
route.exe
routemon.exe
rsh.exe
rsm.exe
runas.exe
sc.exe
schtasks.exe
secedit.exe
sfc.exe
shift.exe
shutdown.exe
sort.exe
start.exe
subst.exe
systeminfo.exe
taskkill.exe
tasklist.exe
tcmsetup.exe
telnet.exe
tftp.exe
time.exe
title.exe
tracerpt.exe
tracert.exe
tree.exe
type.exe
typeperf.exe
unlodctr.exe
ver.exe
verify.exe
vol.exe
vssadmin.exe
w32tm.exe
wmic.exe
xcopy.exe


And then outputs a text file (which pops up for viewing)
listing all the missing files.


for example:

Code: Select all

LISTING OF MISSING FILES

findstr.exe
mountvol.exe
popd.exe
shift.exe
vssadmin.exe
xcopy.exe


or else, for example:

Code: Select all

LISTING OF MISSING FILES

There are no files missing.

I don't know how to construct such a batch file.
Is this pretty straightforward or is it a curly one?
Thanks for your time.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: List all "Command Line" System Files - Compare to my list

#2 Post by aGerman » 25 Jan 2010 17:49

Hi thr333,

first let me say there are a lot of mistakes in your list. Not every command is an EXE file. Some (like ECHO, FOR, TIME, PUSHD, POPD ...) are implemented to the command line interpreter, some other (like GRAFTABL, MODE, MORE ...) are COM files. So figure out on your system and change it.
An other aspect you should make sure is that the called command line interpreter is cmd.exe instead of command.com. Probably start the batch files with

Code: Select all

@echo off &setlocal enableextensions



Okay, next step. Lets say your (changed) list is in "List1.txt". We could write a "List2.txt" with all found EXE and COM files. Compare if all lines of "List1.txt" are found in "List2.txt". If not, write to "List3.txt". At last open "List3.txt". That's what this code will do:

Code: Select all

@echo off &setlocal
type nul>List2.txt
type nul>List3.txt

pushd "%systemroot%\system32"
dir /a-d /b *.exe *.com>>"%~dp0List2.txt"
popd

pushd "%systemroot%\system32\wbem"
dir /a-d /b *.exe *.com>>"%~dp0List2.txt"
popd

for /f "delims=" %%i in (List1.txt) do (
  (find /i "%%i" List2.txt >nul) || echo %%i>>List3.txt)
 
start List3.txt


Regards
aGerman

thr333
Posts: 16
Joined: 24 Aug 2009 10:24

Re: List all "Command Line" System Files - Compare to my list

#3 Post by thr333 » 26 Jan 2010 09:18

aGerman, your code works nicely, congratulations ++++
It's nicely written too; it looks clean and uncluttered ++++

Could you show us how to extend the code...

What I mean is (I know this is laborious) to add the list (of List1.txt) into the batch file itself
and to also dump 'List2.txt' and 'List3.txt' into the %Temp% folder.
This way, I have no need for the text files and the batch file is standalone.
I'm guessing we need to create a :loop (label) somewhere with that list from List1.txt. Yes?

Thanks.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: List all "Command Line" System Files - Compare to my list

#4 Post by aGerman » 26 Jan 2010 13:00

Hi thr333.

I see two ways.
1st Set each file name into a variable and
2nd Mark off each line to use FINDSTR for the own batch code.
IMHO the second would be better.
For testings:

Code: Select all

@echo off &setlocal
set "all=%temp%\all.txt"
set "missing=%temp%\missing.txt"

type nul>"%all%"
echo LISTING OF MISSING FILES>"%missing%"
echo.>>"%missing%"

pushd "%systemroot%\system32"
dir /a-d /b *.exe *.com>>"%all%"
popd

pushd "%systemroot%\system32\wbem"
dir /a-d /b *.exe *.com>>"%all%"
popd

set n=0
for /f "delims=: tokens=2" %%i in ('findstr /l /b /c:"*:" "%~0"') do (
  (find /i "%%i" "%all%" >nul) || (echo %%i>>"%missing%" &set /a n+=1))

if %n%==0 echo There are no files missing.>>"%missing%"

start "" "%missing%"

ping -n 3 localhost>nul
del "%all%"
del "%missing%"

goto :eof

:: default list:
*:ping.exe
*:for.exe
*:command.com
*:if.com


Don't forget the "goto :eof" command line before starting your list.
Place *: before each file name you're looking for.
This example should put for.exe and if.com into the missings list, because they will never exist.

Regards
aGerman

thr333
Posts: 16
Joined: 24 Aug 2009 10:24

Re: List all "Command Line" System Files - Compare to my list

#5 Post by thr333 » 28 Jan 2010 12:07

Thanks again aGerman, your code works great straight out of the box +++++

I'm in the process of compiling a definitive list of the 'correct' files to look for,
it's taking long time; I'm double checking everything !
I'll update my 2nd post when I do.

One last thing if you don't mind...
Could you explain line-by-line how the syntax flow is working in your second batch code.
I'm asking you this because I can't follow the syntax flow in some lines (I'm a noob).

Thanks again for all your time and wonderful coding +++

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: List all "Command Line" System Files - Compare to my list

#6 Post by aGerman » 28 Jan 2010 17:57

Hi thr333,
I will try to explain, but please note that English isn't my native language. So don't hesitate to ask if something isn't clear to you.

Code: Select all

@echo off &setlocal

Hide the command prompt and limit the change in the environment to the current batch window.

Code: Select all

set "all=%temp%\all.txt"
set "missing=%temp%\missing.txt"

Set the full names of the temporary text files to variables.

Code: Select all

type nul>"%all%"

NUL is a imaginary machine. Imagine, it would be a "black hole". Redirect something to NUL, it would be gulped by the black hole. Try to get something from NUL and you will get NOTHING :wink:
This line does nothing but writing a blank zero byte file (or overwrite if exist).

Code: Select all

echo LISTING OF MISSING FILES>"%missing%"
echo.>>"%missing%"

First line writes or overwrites (because of ">") the new file with the echoed text.
Second line appends (because of ">>") a blank line.

Code: Select all

pushd "%systemroot%\system32"

Change the directory.

Code: Select all

dir /a-d /b *.exe *.com>>"%all%"

Find all EXE and COM files into the current directory.
/a-d means ignore directories
/b return file names only, without header, footer and further informations
>> append the StdOut to all.txt

Code: Select all

popd

Change back to the origin directory

Code: Select all

pushd "%systemroot%\system32\wbem"
dir /a-d /b *.exe *.com>>"%all%"
popd

Just the same again with wbem.

Code: Select all

set n=0

To count the missing files I want to start with 0.

Code: Select all

for /f "delims=: tokens=2" %%i in ('findstr /l /b /c:"*:" "%~0"') do (
  (find /i "%%i" "%all%" >nul) || (echo %%i>>"%missing%" &set /a n+=1))

This is something like the "core process" and realy not easy to explain.
First you have to know that the "own calling" of your batch file is the content of %0. Maybe for your understanding it would be better to say it contains the full name of itself.
This fact is our advantage to use FINDSTR for the own batch code. So we're looking for each line starting with "*:". The FOR loop splits each found string by using the colon ( delims=: ) and returns the second half ( tokens=2 ) to %%i. Now %%i contains (with each iteration) one of your default app names of your list.
The next step is looking for %%i in all.txt. If this is not successful ( || ) append %%i to the list of missings and increment n.

Code: Select all

if %n%==0 echo There are no files missing.>>"%missing%"

If no app name was missing then n equals 0 ...

Code: Select all

start "" "%missing%"

Open missing.txt using the default app (probably notepad.exe).

Code: Select all

ping -n 3 localhost>nul

Wait 2 seconds while notepad opens.

Code: Select all

del "%all%"
del "%missing%"

Delete the temporary files (although notepad has opened one it works).

Code: Select all

goto :eof

:EOF is an imaginary label and means "End Of File". Using this line all lines after will be ignored by the command line interpreter.

Code: Select all

:: default list:
*:ping.exe
*:for.exe
*:command.com
*:if.com

Your list...

I hope it will help to understand the way it workes.

Regards
aGerman

Post Reply