spacesurfer Posted September 3, 2006 Share Posted September 3, 2006 I'm trying to install Grub in unattended setup. My script replaces ntldr with grub. However, I want to check the size of ntldr with a script.I have used the script below and it works flawlessly in Windows 2000. However, in Windows XP, it doesn't work. Anyone know why the difference in the two?Here is the script:echo.@echo offset tags=boot.ini ntldrfor %%I in (%tags%) do call :setvars %%I:setvarsfor %%J in (Z Y W X W V U T S R Q P O N M L K J I H G F E D C) do if exist "%%J:%%I" set %%I=%%J: &&set %%Iz=%%~zIecho.echo.echo ntldr location is %ntldr%echo boot.ini location is %boot.ini%echo.echo Size of ntldr is %ntldrz%echo Size of boot.ini is %boot.iniz%pausegoto :eofIt correctly finds the location of ntldr, but %~zI is not expanded with filesize. So all I get is:Size of ntldr is Link to comment Share on other sites More sharing options...
Delprat Posted September 3, 2006 Share Posted September 3, 2006 In the :setvars proc, %%I becomes %1. (depending on commandline extensions)How come you batch finds the ntldr location ????? ++ Link to comment Share on other sites More sharing options...
Yzöwl Posted September 3, 2006 Share Posted September 3, 2006 My learned friend is correct, that file will not work flawlessly!here is an alternative method for you@ECHO OFF &SETLOCAL ENABLEEXTENSIONSFOR /F %%? IN ('MOUNTVOL^|FIND ":\"') DO (CALL :GETSIZE %%?)ECHO/&ECHO/ ntldr location is %ntldr%ECHO/ boot.ini location is %boot.ini%ECHO/&ECHO/ Size of ntldr is %ntldrz% bytesECHO/ Size of boot.ini is %boot.iniz% bytesPAUSE &ENDLOCAL &GOTO :EOF:GETSIZEPUSHD %1 2>NULFOR %%? IN (BOOT.INI NTLDR) DO (IF EXIST %%? ( SET "%%?=%CD:~0,2%" &SET "%%?z=%%~z?"))POPD &GOTO :EOF Link to comment Share on other sites More sharing options...
jaclaz Posted September 3, 2006 Share Posted September 3, 2006 (edited) Also, it (the original one, I mean, Yzowl beat me on time) loops more times than needed.See if this works:@echo offfor %%A in (Z Y W X W V U T S R Q P O N M L K J I H G F E D C) do call :setvars %%A:\ntldr %%A:\boot.inipausegoto :eof:setvarsif exist %1 (if exist %2 (echo.echo.echo %1 size is %~z1echo %2 size is %~z2echo.))goto :eofthis one checks if BOTH boot.ini and NTLDR are present.jaclazP.S.: reference:http://www.robvanderwoude.com/ntcall.html Edited September 3, 2006 by jaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted September 3, 2006 Share Posted September 3, 2006 If both files are expected on the same drive then jaclaz' solution will serve you a little better.The only thing that I'm wondering is why Z»C as opposed to C»ZThe following version will break out of the loop as soon as the files are found:@ECHO OFFFOR %%? 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 ( CALL :SETVARS %%?:\NTLDR %%?:\boot.ini ||GOTO :ABORT):ABORTPAUSE &GOTO :EOF:SETVARSIF EXIST %1 (IF EXIST %2 ( ECHO/&ECHO/%1 size is %~z1 bytes&ECHO/%2 size is %~z2 bytes&ECHO/&&EXIT/B 1))EXIT/B 0What that means is that as soon as boot.ini and NTLDR are found on the same drive it will not continue checking any remaining drives.You can of course still have your drive letters in whichever order you prefer! Link to comment Share on other sites More sharing options...
spacesurfer Posted September 4, 2006 Author Share Posted September 4, 2006 (edited) You read my mind Yzowl. If I went from C > Z, then it finds the last drive that has those files, which is what I didn't want. That's why I changed it from Z > C. Thanks for your better script, I will try it.Other things is that it does work in Windows 2000 *flawlessly.* I've tried it at work just the way I posted it. Then I tried the same script at home on my XP and it finds the location but does not expand the size.It's strange.I'll try your last script though.Edit:Your last scripts works, Yzowl. And it breaks the loop once it finds the drive.Thanks, again.It's baffling why my original one finds location but not the size.... I tried replacing I with 1 as Delprat mentioned, but that doesn't work at all. With 1, it does not even find the location. That's why I used I. Edited September 4, 2006 by spacesurfer Link to comment Share on other sites More sharing options...
Delprat Posted September 4, 2006 Share Posted September 4, 2006 It's baffling why my original one finds location but not the size.... I tried replacing I with 1 as Delprat mentioned, but that doesn't work at all. With 1, it does not even find the location. That's why I used I.Batches are strange sometimes... Try to qualify the pathes instead of supposing that the CD on each drive is the root (you just need to CALL :setvars \%%I --- but I dunno if the SET %1=... still works with %1 starting with a backslash).Same bug for the size : to get %~z1 working, %1 must allow the OS to locate the file, thus the CD matter if %1 doesn't have path ("X:" is only a drivespec, not a path on that drive). (and sometimes it just doesn't work -- ex. in a for /f loop with a dir /b command)I still don't understand how come this works on Win2K. It must be bugged ++ Link to comment Share on other sites More sharing options...
jaclaz Posted September 4, 2006 Share Posted September 4, 2006 I still don't understand how come this works on Win2K. It must be buggedJust for the record it does not work fully in win2k, or at least it does not work how it should.Here is the output of the original script when run for the first time in a newly open box in Win2K(I omitted the PAUSE statements and took out some line feeds):O:\>tntoriO:\>echo.ntldr location isboot.ini location is C:Size of ntldr isSize of boot.ini is 171ntldr location is C:boot.ini location is C:Size of ntldr is 215472Size of boot.ini is 171ntldr location is C:boot.ini location is C:Size of ntldr is 215472Size of boot.ini is 171Whilst here is the one from my script (I have a copy of NTLDR/BOOT.INI in O:\) :O:\>tntO:\ntldr size is 215472O:\boot.ini size is 171C:\ntldr size is 215472C:\boot.ini size is 741And the one from first Yzowl one, (I don't like using MOUNTVOL as it accesses the floppy):O:\>tnt2 ntldr location is O: boot.ini location is O: Size of ntldr is 215472 bytes Size of boot.ini is 171 bytesAnd the one from 2nd Yzowl one:O:\>tnt3C:\NTLDR size is 215472 bytesC:\boot.ini size is 741 bytesjaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted September 4, 2006 Share Posted September 4, 2006 I don't like using MOUNTVOL as it accesses the floppyI guess that its part of explorer /Windows GUI which accesses the drive; so in testing, to prevent it, I usually use('MOUNTVOL^|FIND ":\"^|FIND /V "A:\"')During setup the GUI is not loaded so the floppy drive is not accessed and the script I suggested is fine. Link to comment Share on other sites More sharing options...
spacesurfer Posted September 5, 2006 Author Share Posted September 5, 2006 Yzowl, your script in post #3 gives me extra spaces and it fails.What is does is:for ntldr do if exist " C:\ntldr"....There are spaces after the first quotation. It's strange.Is MY windows bugged? Link to comment Share on other sites More sharing options...
Yzöwl Posted September 5, 2006 Share Posted September 5, 2006 Well if you have copied and pasted correctly and you have not altered my code, then I suppose it must be.I can say that because as you can see from my posting, it says (IF EXIST %%? (not (IF EXIST " %%?" ( Link to comment Share on other sites More sharing options...
spacesurfer Posted September 5, 2006 Author Share Posted September 5, 2006 I copied it exactly. I didn't retype it. Your scripts are baffling... they seem to work, except this one... I'll work on it some more to see what's wrong.Anyway, I found one script on this page that works.Thanks. Link to comment Share on other sites More sharing options...
Yzöwl Posted September 5, 2006 Share Posted September 5, 2006 Not only do all of the scripts, (except for yours), work for me, they do, (with results published to prove it), for jaclaz too! Link to comment Share on other sites More sharing options...
gunsmokingman Posted September 5, 2006 Share Posted September 5, 2006 I tested Yzöwl script on XP and it work but on Vista I get thisHere is a VBS script that only checks the harddrives for the 2 files. This worked on Both XP and Vista.Save As Check_BootIni_Ntldr.vbsDim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")Dim Act : Set Act = CreateObject("Wscript.Shell")Dim Cmd1, Cmd2, F1, F2, KB, Lb1, Lb2Cmd1 = "Attrib.exe -h -s " : Cmd2 = "Attrib.exe +h +s " : KB = 1024Lb1 = " File Path " : Lb2 = " File Size " : F1 = "\boot.ini" : F2 = "\ntldr"Dim ChkFile, Drv, File, Rpt, Rpt1, StrD Set Drv = Fso.Drives For Each StrD In Drv If StrD.DriveType = 2 Then Act.Run(Cmd1 & StrD & F1),0,True : Act.Run(Cmd1 & StrD & F2),0,True '/-> Remove Attributes If Fso.FileExists(StrD & F1) Then ChkFile = StrD & F1 : SortTheFileSize() Rpt1 = Rpt1 & vbCrLf & Rpt : Act.Run(Cmd2 & StrD & F1),0,True '/-> Replace Attribute End If If Fso.FileExists(StrD & F2) Then ChkFile = StrD & F2 : SortTheFileSize() Rpt1 = Rpt1 & vbCrLf & Rpt : Act.Run(Cmd2 & StrD & F2),0,True '/-> Replace Attribute End If End If Next Function SortTheFileSize() '/-> Checks File Size Sorts The Size Set File = Fso.GetFile(ChkFile) : Rpt = Lb1 & File.Path & vbCrLf & Lb2 If File.Size < 1024 Then Rpt = Rpt & File.Size & " Bites" & vbCrLf End If If File.Size > 1024 Then Rpt = Rpt & Left(File.Size/KB,5) & " KB" & vbCrLf End If End Function MsgBox Space(7) & "Found Files" & Rpt1 , 0 + 32 + 4096, "Report Files" '/-> Reports The Drive Link to comment Share on other sites More sharing options...
Yzöwl Posted September 6, 2006 Share Posted September 6, 2006 @ECHO OFFFOR %%? 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 ( CALL :SETVARS %%?:\NTLDR %%?:\boot.ini ||GOTO :ABORT):ABORTPAUSE &GOTO :EOF:SETVARSIF EXIST %1 (IF EXIST %2 ( ECHO/&ECHO/%1 size is %~z1 bytes&ECHO/%2 size is %~z2 bytes&ECHO/&&EXIT/B 1))EXIT/B 0@ECHO OFFFOR %%? 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 ( CALL :SETVARS %%?:\NTLDR %%?:\boot.ini ||GOTO :ABORT):ABORTPAUSE &GOTO :EOF:SETVARSIF EXIST %1 (IF EXIST %2 ( ECHO/&ECHO/%1 size is %~z1 bytes&ECHO/%2 size is %~z2 bytes&ECHO/&&EXIT/B 1))EXIT/B 0Look at line 6 and then tell me why you get the error 'The system canot find the batch label specified - SETVARS' 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