Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Syntax on Set command is not correct

68 views
Skip to first unread message

Docfxit

unread,
Aug 6, 2016, 3:57:12 PM8/6/16
to
Could 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
Set drive=F:
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

This is what I am getting as output:
H:
:\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

JJ

unread,
Aug 6, 2016, 5:17:18 PM8/6/16
to
The syntax is correct. You just didn't assign it with the correct value and
the paths used for the COPY commands is incorrect.

Replace (no quotes) "echo %%i" with "Set CDDrive=%%i".
Delete the "Set CDDrive=%1" line.
Delete all colons in the lines with the COPY command.
Delete the last line unless you know what you're doing.

Docfxit

unread,
Aug 6, 2016, 8:22:42 PM8/6/16
to
Thank you JJ...
That is a lot closer to working. I'm still having trouble with the copy statement.
The first value is showing as %1 and should be H:

(
if [%%j]==[5] Set CDDrive=%%1
)

Shows in cmd window as:
COPY %1\I386\NTLDR F:\

Thanks,
Docfxit

Thomas Langer

unread,
Aug 7, 2016, 6:42:10 AM8/7/16
to
In the for-loop you are assigning values to the variable %%i. Therefore
you should assign the Contents of %%i to CDDrive, not %1, i.e. the first
argument of your script. Typo?

Regards
Thomas

foxidrive

unread,
Aug 7, 2016, 3:38:44 PM8/7/16
to
On 7/08/2016 20:42, Thomas Langer wrote:
> In the for-loop you are assigning values to the variable %%i. Therefore
> you should assign the Contents of %%i to CDDrive, not %1, i.e. the first
> argument of your script. Typo?
>
> Regards
> Thomas

Good point there.

Back in the dark ages it was impressed upon programmers to avoid using
variable names of i I 1 l L 0 O o because they can look the same in
different fonts and so cause premature balding.





petu...@googlemail.com

unread,
Aug 7, 2016, 3:41:38 PM8/7/16
to
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%).

Docfxit

unread,
Aug 7, 2016, 10:26:05 PM8/7/16
to
This will be really great once it's working correctly.
Currently it it's producing the correct drive letter.
This is the output:
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"

C:\Dnload>For %b In (H:
) 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

petu...@googlemail.com

unread,
Aug 8, 2016, 4:11:36 AM8/8/16
to
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 ------

Docfxit

unread,
Aug 9, 2016, 1:15:58 PM8/9/16
to
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

foxidrive

unread,
Aug 9, 2016, 2:00:11 PM8/9/16
to
On 10/08/2016 03:15, Docfxit wrote:

> I have discovered when I run
> Bootrec /scanos
> If it returns Total identified Windows installations: 0
> I need to run some additional code.
>
>
> 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

Test this: The output from 'bootrec' looks to be UNICODE.

It will always skip the rebuild code if the 'find' command doesn't
interpret the message as shown. findstr may be another option rather than
'find'.



@echo off
Bootrec /scanos |find /i "Windows installations: 0" >nul || goto :skip
set "ask="
set /p "ask=No installations found: type YES to rebuild BCD: "
if /i not "%ask%"=="YES" goto :skip
bcdedit /export c:\bcdbackup
attrib c:\boot\bcd -h -r -s
ren C:\boot\bcd bcd.old
bootrec /rebuildbcd
:skip
rem continue with commands here.




Docfxit

unread,
Aug 9, 2016, 4:48:47 PM8/9/16
to
Thank you for the code...

I tried it as is and it didn't find "Windows installations: 0"
I tried it with findstr and it gave me an error saying:
'findstr' is not recognized as an internal or external command.

I tried this code as a test to make sure the correct info was displayed during the execution:

:: Begin of code
Echo (BOOTREC /SCANOS
Bootrec /scanos
Bootrec /scanos |find /i "Windows installations: 0" || goto :skip
set "ask="
set /p "ask=No installations found: type YES to rebuild BCD: "
if /i not "%ask%"=="YES" goto :skip
bcdedit /export c:\bcdbackup
attrib %ToDrive%:\boot\bcd -h -r -s
ren %ToDrive%:\boot\bcd bcd.old
bootrec /rebuildbcd
:skip
::End of code

Thanks,

Docfxit

foxidrive

unread,
Aug 9, 2016, 6:00:10 PM8/9/16
to
On 10/08/2016 03:15, Docfxit wrote:

> I have discovered when I run
> Bootrec /scanos
> If it returns Total identified Windows installations: 0
> I need to run some additional code.
>
>
> 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

I'm responding to your reply here:

The output from 'bootrec' looks to be UNICODE.
Or it could be a form of UTF encoding


findstr may not be available in the recovery environment.
I'm not sure what batch features the recovery environment will be missing.


Try both these:



@echo off
Bootrec /scanos >file.txt
type file.txt |find /i "Windows installations: 0" >nul || goto :skip
set "ask="
set /p "ask=No installations found: type YES to rebuild BCD: "
if /i not "%ask%"=="YES" goto :skip
bcdedit /export c:\bcdbackup
attrib c:\boot\bcd -h -r -s
ren C:\boot\bcd bcd.old
bootrec /rebuildbcd
:skip
del file?.txt
rem continue with commands here.




@echo off
Bootrec /scanos >file.txt
type file.txt >file2.txt
type file2.txt|find /i "Windows installations: 0" >nul || goto :skip
set "ask="
set /p "ask=No installations found: type YES to rebuild BCD: "
if /i not "%ask%"=="YES" goto :skip
bcdedit /export c:\bcdbackup
attrib c:\boot\bcd -h -r -s
ren C:\boot\bcd bcd.old
bootrec /rebuildbcd
:skip
del file?.txt

Docfxit

unread,
Aug 9, 2016, 9:00:21 PM8/9/16
to
Thanks for putting this together for me.

They both seem to work.

The file.txt output from the first one is:
Scanning all disks for Windows installations.

Please wait, since this may take a while...

Successfully scanned Windows installations.
Total identified Windows installations: 0
The operation completed successfully.

This is the output from file2.txt on the second one.
Scanning all disks for Windows installations.

Please wait, since this may take a while...

Successfully scanned Windows installations.
Total identified Windows installations: 0
The operation completed successfully.

Thanks,

Docfxit

foxidrive

unread,
Aug 10, 2016, 8:05:35 AM8/10/16
to
On 10/08/2016 11:00, Docfxit wrote:
>>
>> The output from 'bootrec' looks to be UNICODE.
>> Or it could be a form of UTF encoding

It was UTF by the look of it and TYPE is able to convert a form of that.
Adding the type command was the only change.

>> @echo off
>> Bootrec /scanos >file.txt
>> type file.txt |find /i "Windows installations: 0" >nul || goto :skip
>> set "ask="
>> set /p "ask=No installations found: type YES to rebuild BCD: "
>> if /i not "%ask%"=="YES" goto :skip
>> bcdedit /export c:\bcdbackup
>> attrib c:\boot\bcd -h -r -s
>> ren C:\boot\bcd bcd.old
>> bootrec /rebuildbcd
>> :skip
>> del file?.txt
>> rem continue with commands here.
>
> Thanks for putting this together for me.
> They both seem to work.

No worries, thanks for your feedback.
They both do the same thing essentially and the first one is the simpler
version.



You may like to try replacing this command with the one beneath it.
ren C:\boot\bcd bcd.old

ren C:\boot\bcd bcd-%random%%random%%random%.old


That should allow you to run the script a few times, if needed, and saves
the BCD file each time with a random number (three are used to give a good
chance of avoiding filename collisions).

The date-time stamp will show which BCD file is the earliest/latest.


> The file.txt output from the first one is:
> Scanning all disks for Windows installations.
>
> Please wait, since this may take a while...
>
> Successfully scanned Windows installations.
> Total identified Windows installations: 0
> The operation completed successfully.
>
> Thanks,
>
> Docfxit


Docfxit

unread,
Aug 10, 2016, 6:24:03 PM8/10/16
to
On Saturday, August 6, 2016 at 12:57:12 PM UTC-7, Docfxit wrote:
I am working on debugging the bat file. On the screen output it shows:
either an error or something completed successfully.
I am currently adding:
Echo (and the command
to every line that has a command in order to figure out where the errors are coming from.
One error is:
The system cannot find the file specified

There must be a better way to show the command along with the error so I don't have to place an Echo in front of every command.

Thanks,

Docfxit

foxidrive

unread,
Aug 11, 2016, 3:50:02 AM8/11/16
to
On 11/08/2016 08:24, Docfxit wrote:
> I am working on debugging the bat file. On the screen output it shows:
> either an error or something completed successfully.
> I am currently adding:
> Echo (and the command
> to every line that has a command in order to figure out where the errors are coming from.
> One error is:
> The system cannot find the file specified
>
> There must be a better way to show the command along with the error so I don't have to place an Echo in front of every command.

Place a pause command above and below the suspect sections and you'll be
able to narrow down which area it is in.


Removing the "@echo off" or changing it to "@echo on" or put "echo on" on
the next line is another way to see the commands as they run.

That can be confusing to read but adding pause commands can limit how much
runs between the pause commands.



0 new messages