Post by p***@googlemail.comPost by DocfxitPost by p***@googlemail.comPost by DocfxitCould someone please help me correct the syntax of set CDDrive and Set drive. It's not showing correctly in the copy statements. I'm running this after booting up to a Win 10 CD in cmd prompt after selecting repair.
@echo off
setlocal
for /f "skip=1 tokens=1,2" %%i in ('wmic logicaldisk get caption^, drivetype') do (
if [%%j]==[5] echo %%i
Set CDDrive=%1
)
COPY %CDDrive%:\I386\NTLDR %drive%\
COPY %CDDrive%:\I386\NTDETECT.COM %drive%\
endlocal
@CMD > Null
:\I386\NTLDR
The filename, directory name, or volume label syntax is incorrect.
0 file(s) copied.
:\I386\NTDETECT.COM
The filename, directory name, or volume label syntax is incorrect.
0 file(s) copied.
exit
C:\Dnload>bootfixer3>bootfix3.txt
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
Thank you,
Docfxit
The following example should only assign the %CDDrive% variable if your source folder exists on a readable optical drive.
::----- START SCRIPT -----
@Echo Off
SetLocal
Set "ToDrive=F:\"
Set "CDDrive="
For /F "Tokens=*" %%a In ('WMIC LogicalDisk WHERE^
"DriveType=5 AND Access=1 OR Access=3" Get Caption 2^>Nul') Do For %%b In (
%%a) Do If Exist %%b\I386\ Set "CDDrive=%%b"
If Not Defined CDDrive Exit/B
If Exist %CDDrive%\I386\NTLDR Copy %CDDrive%\I386\NTLDR %ToDrive%
If Exist %CDDrive%\I386\NTDETECT.COM Copy %CDDrive%\I386\NTDETECT.COM %ToDrive%
::------ END SCRIPT ------
I think I'd also be looking into a method of dynamically assigning your currently hard coded destination drive, (%ToDrive%).
This will be really great once it's working correctly.
Currently it it's producing the correct drive letter.
C:\Dnload>Set "CDDrive="
C:\Dnload>For /F "Tokens=*" %a In ('WMIC LogicalDisk WHERE "DriveType=5 AND Access=1 OR Access=3" Get Caption 2>Nul') Do For %b In (%a) Do If Exist %b\I386\ Set "CDDrive=%b"
C:\Dnload>For %b In (Caption
) Do If Exist %b\I386\ Set "CDDrive=%b"
C:\Dnload>If Exist Caption\I386\ Set "CDDrive=Caption"
) Do If Exist %b\I386\ Set "CDDrive=%b"
C:\Dnload>If Exist H:\I386\ Set "CDDrive=H:"
C:\Dnload>For %b In (
) Do If Exist %b\I386\ Set "CDDrive=%b"
C:\Dnload>Echo
ECHO is on.
C:\Dnload>If Not Defined CDDrive Exit/B
My output: (as also seen here http://imgur.com/a/4j0jY)
::----- START -----
C:\Users\Peturbed>SetLocal
C:\Users\Peturbed>Set "ToDrive=F:\"
C:\Users\Peturbed>Set "CDDrive="
C:\Users\Peturbed>For /F "Tokens=*" %a In ('WMIC LogicalDisk WHERE "DriveType=5
AND Access=1 OR Access=3" Get Caption 2>Nul') Do For %b In (%a) Do If Exist %b\I
386\ Set "CDDrive=%b"
) Do If Exist %b\I386\ Set "CDDrive=%b"
C:\Users\Peturbed>If Exist Caption\I386\ Set "CDDrive=Caption"
) Do If Exist %b\I386\ Set "CDDrive=%b"
C:\Users\Peturbed>If Exist D:\I386\ Set "CDDrive=D:"
) Do If Exist %b\I386\ Set "CDDrive=%b"
C:\Users\Peturbed>If Not Defined CDDrive Exit/B
C:\Users\Peturbed>If Exist D:\I386\NTLDR Echo(Copy D:\I386\NTLDR F:\
Copy D:\I386\NTLDR F:\
C:\Users\Peturbed>If Exist D:\I386\NTDETECT.COM Echo(Copy D:\I386\NTDETECT.COM F
:\
Copy D:\I386\NTDETECT.COM F:\
C:\Users\Peturbed>
::------ END ------
You are super. This is really great. I found my error. You are 100% correct.
Thank you very much for the great code.
I have discovered in order to repair the boot records I need to run some more commands. I would really like to automate these if I can. If you would like I can start a new thread or we can continue this thread. If we continue this thread when we are done I can post the complete bat file I have with other steps I have taken to repair the boot record.
I have discovered when I run
Bootrec /scanos
If it returns Total identified Windows installations: 0
I need to run some additional code.
The exact output I get is:
C:\Dnload>BOOTREC /SCANOS
S c a n n i n g a l l d i s k s f o r W i n d o w s i n s t a l l a t i o n s .
P l e a s e w a i t , s i n c e t h i s m a y t a k e a w h i l e . . .
S u c c e s s f u l l y s c a n n e d W i n d o w s i n s t a l l a t i o n s .
T o t a l i d e n t i f i e d W i n d o w s i n s t a l l a t i o n s : 0
T h e o p e r a t i o n c o m p l e t e d s u c c e s s f u l l y .
The only time I need to add this code is when number of installations is zero.
If the number is one I don't need to add the code.
The code I need to add is:
:: Beginning of code
bcdedit /export c:\bcdbackup
attrib c:\boot\bcd -h -r -s
ren C:\boot\bcd bcd.old
bootrec /rebuildbcd
:: End of code
Which should produce this in the Command Prompt window:
Scanning all disks for Windows installations.
Please wait, since this may take a while...
Successfully scanned Windows installations.
Total identified Windows installations: 1
[1] D:\Windows
Add installation to boot list? Yes<Y>/No<N>/All<A>:
I think I should choose this manually and it not be automated.
Thank you very much,
Docfxit