CMD: Copy files that are listed in a text file.

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

DarkCrystal

Thread Starter
Joined
Jan 28, 2005
Messages
62
Situation: I have the simple CMD(DOS) .bat below that i am using to scan networked computers for specific files that need to be overwritten. When the file is found, its path is appended to the resutls log (MS08-070_compname.txt). I am trying to figure out how to read that results log to automatically overwrite those files with the updated files.

Limits: Cannot use any third-party software, cannot use GPO, pretty much can't use much else than the DOS CLI basically. A HUGE! annoyance, trust me, I know. I am quite aware of how old the DOS CLI is and that there are much better tools out there, I just simply cannot use them due to implemented network limitations.

Thanks in advance for any help provided!


@echo off


:start
cls
set /p cname="What is the computer name to search? \\"


:search
echo.
echo Now searching for ComCt232.ocx (1 of 8) . . .
dir \\%cname%\c$\ComCt232.ocx /b /s > %userprofile%\MS08-070_%cname%.txt
echo Now searching for MSChrt20.ocx (2 of 8) . . .
dir \\%cname%\c$\MSChrt20.ocx /b /s >> %userprofile%\MS08-070_%cname%.txt
echo Now searching for mscomct2.ocx (3 of 8) . . .
dir \\%cname%\c$\mscomct2.ocx /b /s >> %userprofile%\MS08-070_%cname%.txt
echo Now searching for MSDatGrd.ocx (4 of 8) . . .
dir \\%cname%\c$\MSDatGrd.ocx /b /s >> %userprofile%\MS08-070_%cname%.txt
echo Now searching for MSFlxGrd.ocx (5 of 8) . . .
dir \\%cname%\c$\MSFlxGrd.ocx /b /s >> %userprofile%\MS08-070_%cname%.txt
echo Now searching for MShflxgd.ocx (6 of 8) . . .
dir \\%cname%\c$\MShflxgd.ocx /b /s >> %userprofile%\MS08-070_%cname%.txt
echo Now searching for msmask32.ocx (7 of 8) . . .
dir \\%cname%\c$\msmask32.ocx /b /s >> %userprofile%\MS08-070_%cname%.txt
echo Now searching for MSWINSCK.ocx (8 of 8) . . .
dir \\%cname%\c$\MSWINSCK.ocx /b /s >> %userprofile%\MS08-070_%cname%.txt
echo.
echo Results published to: %userprofile%\MS08-070_%cname%.txt
set /p ="Search complete! Press [Enter] to close"
 
Joined
Aug 7, 2007
Messages
9,028
Instead of doing 8 full searches of the drive, be more efficient to search once and find the filenames you want:
Code:
@Echo Off
:start
cls
Set /P cname="What is the computer name to search? \\"
:search
Set _Find="ComCt232.ocx MSChrt20.ocx mscomct2.ocx MSDatGrd.ocx MSFlxGrd.ocx MShflxgd.ocx msmask32.ocx MSWINSCK.ocx"
Dir \\%cname%\c$\*.ocx /B /S|Findstr /I %_Find%>"%userprofile%\MS08-070_%cname%.txt"
Echo Results published to: %userprofile%\MS08-070_%cname%.txt
Echo.
Set /P ="Search complete! Press [Enter] to close"
This will then read each file, and copy the new files to the target systems. Put all the new files in the path specified on the Set _NewFiles line.
Code:
@Echo Off
Set _NewFiles=C:\NewFilesHere
For /F "Tokens=* Delims=" %%F In ('Dir "%userprofile%\MS08-070_*.txt"') Do (
  Set _Fname=%%F
  For /F "Tokens=* Delims=" %%I In ('Type "%_Fname%"') Do Copy "%_NewFiles%\%%~nxI" "%%I"
)
 

DarkCrystal

Thread Starter
Joined
Jan 28, 2005
Messages
62
Trimmed my code makin it more efficient AND provided a solution! Thanks a ton! Still got a lot to learn about the CMD interface. Like the answer, just wondering if it's possible to overwrite the files in the exact same locations that they are already in. I'll use what's provided and tinker around, I'm sure I'll get it fingured out! :D

Thanks again!
 

DarkCrystal

Thread Starter
Joined
Jan 28, 2005
Messages
62
Nevermind, I was displaying a lack of thought >_< my bad... Your help has been invaluable!
 
Joined
Aug 7, 2007
Messages
9,028
This does replace the files in their current locations, the %%I in the Copy command is the path to the file on each system.

I can see some issues with this though. If any of those files were updated via Windows Update or the installation of a service pack, the old version would be stored in one of the $NTUninstallXXXXX$ folders (Windows XP, Vista and later are different, they use the WinSxS folder). This will replace those older versions which means uninstalling an update could make the system unstable, as the older version won't be restored. Same with the $hf_mig$ folder, which is used to insure version mismatches aren't created by future updates.
You can exclude those folders with this version:
Code:
@Echo Off
:start
cls
Set /P cname="What is the computer name to search? \\"
:search
Set _Find="ComCt232.ocx MSChrt20.ocx mscomct2.ocx MSDatGrd.ocx MSFlxGrd.ocx MShflxgd.ocx msmask32.ocx MSWINSCK.ocx"
Set _Exclude=/C:"$hf_mig$" /C:"$NTUninstall"
Dir \\%cname%\c$\*.ocx /B /S|Findstr /I /V %_Exclude%|Findstr /I %_Find%>"%userprofile%\MS08-070_%cname%.txt"
Echo Results published to: %userprofile%\MS08-070_%cname%.txt
Echo.
Set /P ="Search complete! Press [Enter] to close"
You can exclude addition folders by adding additional masks to the Set _Exclude= line:
/C:"foldermask"

Be sure there is a space before the /C

Also, Windows File Protection might not let you change the file if those particular ones are protected. I don't have any of those files on my system, so I couldn't test that.
It may replace the changed version with the backup copy from the dllcache before that backup copy gets replaced, so while you think you've updated the file, Windows may have reverted it silently.
If you manage to replace both, if the version catalog isn't updated, WFP will continually prompt you to insert the CD so it can replace the file that was changed.

Hopefully won't be a problem with your setup, but something to be aware of, and to test for.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top