sixpack Posted November 27, 2004 Share Posted November 27, 2004 is there someone that can write a batch or a vbs script for me?the script must scan multipule harddrives in search of a file, lets say bla.dllit must replace the "bla.dll" and back up the old one like "bla.dll.bak"and ad some message like file not found in the scriptthe new "bla.dll" is in the same folder as the batch and or vbs filecan a script wizard help me with this? thanks for reading this sorry for the verry bad english Link to comment Share on other sites More sharing options...
Doggie Posted November 28, 2004 Share Posted November 28, 2004 Using VBScript and the FileSystemObject to Replace Batch Fileshttp://windows.oreilly.com/news/vbscriptpr_0201.htmlCode examplehttp://www.windowsdevcenter.com/examples/w...iptpr_code.htmlThe code is self explainatory and will help you a fair bit Link to comment Share on other sites More sharing options...
sixpack Posted November 28, 2004 Author Share Posted November 28, 2004 Using VBScript and the FileSystemObject to Replace Batch Fileshttp://windows.oreilly.com/news/vbscriptpr_0201.htmlCode examplehttp://www.windowsdevcenter.com/examples/w...iptpr_code.htmlThe code is self explainatory and will help you a fair bit i did find that site with google to but that is not what i'm looking forbut what i need is scan more hd's, backup, and replace a filei have no experience with vbs scripting so i need some help with it Link to comment Share on other sites More sharing options...
Doggie Posted November 28, 2004 Share Posted November 28, 2004 well i'll help as much as i canfor a start, the code can be modified like thisCheckFolder (objFSO.getfolder("c:\")), "folder_name\filename"just add the addition line for say for example "D: Drive"CheckFolder (objFSO.getfolder("d:\")), "folder_name\filename"change the extension in the CheckFolder function code fromstrSearch = ".bat"to your desired file type for example "DLL"strSearch = ".dll"And for this section:If UCase(strTemp) = UCase(strSearch) Then'Got one[b]Obviously we need to find an example to copy the original, create the backup and then once thats been done, copy the new file[/b]End IfI'll look for some neccesary functions and examples for you so you can understand some more Link to comment Share on other sites More sharing options...
sixpack Posted November 28, 2004 Author Share Posted November 28, 2004 cool keep it comming edit - i have a runtime error running the orginal script and this one works Dim strName strName = "Matt" Msgbox "Hello " + strName, vbExclamation + _ vbOKOnly, "Test Message Box"Save it on your Windows desktop as test.vbs Link to comment Share on other sites More sharing options...
sixpack Posted November 28, 2004 Author Share Posted November 28, 2004 ok found something:@echo offcolor 1eecho.echo A moment, scanning drive C...echo.for /f "delims=" %%c in ('dir /a /s /b C:\test5.exe') do ( echo þ Found: "%%c", backuped, overwritten copy "%%c" "%%c.OLD" > nul attrib -s -h -r "%%c" copy test5new.exe"%%c" > nul)pauseit does replace the exe file but give's a sintraxis error on file name , hard drive nameany ideas? Link to comment Share on other sites More sharing options...
Doggie Posted November 28, 2004 Share Posted November 28, 2004 arent you missing " <= around the drive name and file name? Link to comment Share on other sites More sharing options...
sixpack Posted November 28, 2004 Author Share Posted November 28, 2004 arent you missing " <= around the drive name and file name?i did mis a space in:copy test5new.exe"%%c" > nulcopy test5new.exe "%%c" > nulbtw works now and backup the old test5.exe to test5.exe.OLD in the same file Link to comment Share on other sites More sharing options...
BritishBulldog Posted November 28, 2004 Share Posted November 28, 2004 here is a vbs script to find all Hard Drivesset WshShell = WScript.CreateObject ("WScript.Shell")Set fso = CreateObject("Scripting.FileSystemObject")'finding HARDDRIVES drive letterFor Each objDrive In fso.Drives If objDrive.DriveType = "2" Then hddrive = objDrive & "\" WshShell.Popup "Your HD is in drive " & hddrive ,,"Find HDD in vbs" End IfNexti am implementing it to the code from the top Code examplehttp://www.windowsdevcenter.com/examples/w...iptpr_code.html Link to comment Share on other sites More sharing options...
sixpack Posted November 28, 2004 Author Share Posted November 28, 2004 ok next question:the batch file works and now i want to ad a error level for file not foundand scan more drive's, and if found stop scanning the other drive's and go to endthis is what i have so far:@echo offcolor 1eecho.echo Een moment, Bezig met het Scannen van Alle Harde Schijven....echo.for /f "delims=" %%t in ('dir /a /s /b C:\test5.exe') do ( echo þ Gevonden: "%%t", Backup Gemaakt, en Overschreven copy "%%c" "%%t.BACKUP" > nul attrib -s -h -r "%%t" copy test5new.exe "%%t" > nul)echo.echo Het Orginele Bestand is Vervangen en van het -echo Oude Bestand is een Backup Gemaakt in de zelfde Map.echo.echo.PAUSEthanks for the info BritishBulldogmaybe someday i learn to write vbs files but i find it to difficult or i'm to stuppit to lear it Link to comment Share on other sites More sharing options...
sixpack Posted November 29, 2004 Author Share Posted November 29, 2004 no one knows? Link to comment Share on other sites More sharing options...
jdoe Posted November 30, 2004 Share Posted November 30, 2004 For the errorlevel I'm not sure what you want, but for ending batch when file found and for checking all hard drives, these lines can do the job...I did not test it so post your result if you need more help.SET PROCESSFILE=test5.exeSET NEWFILE=test5new.exeFOR %%A IN (C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:) DO ( IF EXIST %%A\ ( FOR /F "delims=" %%B IN ('DIR /S /B "%%A\%PROCESSFILE%"') DO ( REN "%%B" "%%~nxB.BACKUP" >NUL COPY "%CD%\%NEWFILE%" "%%B" >NUL GOTO END ) ))ECHO File not foundPAUSE:END Link to comment Share on other sites More sharing options...
sixpack Posted November 30, 2004 Author Share Posted November 30, 2004 THANKS @jdoe the batch scan's all hd's and go's to end when found [cool]but it does not display the "file not found" when not found, the batch goes to endIf the "test5NEW.exe" is not in the same file as the batch it renames the orginal the "test5.exe" to test5.exe.BACKUP[in case if the batch is run] this must not happenquestion:is it posible to display "file not found in D:\"it display's now 5 times file not found [i have 5 hd's]question 2:is it posible to put this piece of code in your patch file to, it displays were the file is found [read errorlog]echo þ found: "%%t",i did try it with your batch file but it does not seam to work.question 3:I want to display in the cmd window when the file is found a few messageslike file found,go get a live or somthing like that when i put in a echo in your batch file it does'nt display itI have also put in my batch file some kind of error log where the file whas foundand have a nice day messageSorry for the many questions but i'm now reading, writing, testing for 3 day's and i cant see any more what i'm doing wrong.My batch file with out your code jdoeit works only it does not scan all hd's and does not display "file not found"["file not found" this is what i mean with errorlevel"]And does not end when the file is foundwy i'm asking all this well when the batch file is perfect other peoplework with it to.thanks again for your help and if you can help me with finishing this batch file i'll hop on a airplane to Cannada and marrie you my batch:@echo offcolor 1eECHO.SET MYLOG="%systemdrive%\Documents and Settings\All Users\Bureaublad\Scan.Log"ECHO Datum: %DATE% - Tijd: %TIME% >>%MYLOG%if not exist test5NEW.exe goto notfoundecho one moment, scanning PC....echo.for /f "delims=" %%t in ('dir /a /s /b C:\test5.exe') do ( echo þ Found: "%%t", and made a Backup copy "%%t" "%%t.BACKUP" > nul attrib -s -h -r "%%t" copy test5new.exe "%%t" > nul)echo.echo. echo. echo Het Orginele Bestand is Vervangen. echo Het Bestand is Overschreven. >>%MYLOG%echo En er is een Backup Gemaakt van het Orginele Bestand in de Zelfde Map. >>%MYLOG%echo.echo have a nice day. echo have a nice day. >>%MYLOG%echo.echo Klaar....echo.echo.echo.goto PAUSEecho.:notfoundCOLOR FCecho ERROR: Het Bestand "test5new.exe", is niet gevonden...!echo ERROR: Het Bestand "test5new.exe", is niet gevonden...! >>%MYLOG%:PAUSEPAUSE Link to comment Share on other sites More sharing options...
sixpack Posted December 8, 2004 Author Share Posted December 8, 2004 DONE THANKS TO THIS FORUMAND:jdoebtw this was build with the stuff i found on the internet and here Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now