Reputation: 520
Comamnd is: reg query \\cois316\hklm\Software\Microsoft\.NETFramework /v EnableIEHosting
and on Windows 7 this works flawlessly, but on XP I get an error that says either "The network path was not found". The hostname is valid on the network and I can ping from my machine to the hostname.
Script this is being used in:
@echo off
cls
:start
echo Main Menu
echo ---------
echo 1) Get Reg Key Status
echo 2) Set Reg Key
echo 3) Exit
echo.
set /p MenuChoice=Choose an option:
IF %MenuChoice% == 1 (
set /p Hostname=Enter Hostname:
REG QUERY \\%Hostname%\HKLM\SOFTWARE\Microsoft\.NETFramework /v EnableIEHosting
goto start
)
IF %MenuChoice% == 2 (
set /p Hostname=Enter Hostname:
REG ADD \\%Hostname%\HKLM\SOFTWARE\Microsoft\.NETFramework /v EnableIEHosting /t REG_DWORD /d
0x00000001
goto start
)
IF %MenuChoice% == 3 (
goto end
)
IF %MenuChoice% == 4 (
set /p Hostname=Enter Hostname:
echo \\%Hostname%\HKLM\SOFTWARE\Microsoft\.NETFramework /v EnableIEHosting
pause
)
cls
goto start
:END
Upvotes: 0
Views: 608
Reputation: 1918
Okay. the problem is within the following block:
IF %MenuChoice% == 1 (
set /p Hostname=Enter Hostname:
REG QUERY \\%Hostname%\HKLM\SOFTWARE\Microsoft\.NETFramework /v EnableIEHosting
goto start
)
Why? As soon the commmand interpreter hits a () block, he automatically resolves all variables contained in this block. That means that the statement set /p Hostname=Enter Hostname:
will work, but the Hostname variable was already resolved. To prove it, try to add an Echo. e.g. ECHO Hostname Entered is: %Hostname%
As soon you queried something and you get back to the :start label, and you query again another server, he's using the previously entered hostname.
To solve this issue, you have to enclose your variables with an exclamation mark. %Hostname%
-> !Hostname!
.
This is only working if you execute the following command initially in your batch file:
SETLOCAL ENABLEDELAYEDEXPANSION
It would work this way:
IF %MenuChoice% == 1 (
set /p Hostname=Enter Hostname:
REG QUERY \\!Hostname!\HKLM\SOFTWARE\Microsoft\.NETFramework /v EnableIEHosting
goto start
)
You have to change this in all other blocks too of course.
I think this would fix your problem on XP.
Upvotes: 1