I have a batch script (that I’m running as a .cmd file through the right-click Send To menu) that first disables a user’s Internet adapter, then securely unzips a .zip archive.
For most people, it’s working great, but I have a couple users who are getting a ‘System cannot find the drive specified’ error, when there’s nothing in there that is looking for a drive.
netsh interface set interface name=”Local Area Connection” admin=disabled
if "%errorlevel%" == "0" ( echo Network Interface disabled ::netsh interface set interface name="Wireless Network Connection" admin=disabled ::if "%errorlevel%" == "1" ( ::echo Network Interface still active, exiting ::pause ::exit b ::) ) ELSE ( echo Network Interface still active pause exit b )
There are some commented out pieces, if the user only has one active Internet connection. The output these two users are getting is:
Network Interface disabled The system cannot find the drive specified. The system cannot find the drive specified. The system cannot find the drive specified. Network Interface still active
So even aside from the fact that I’m not looking for a drive, it shouldn’t be able to echo Network Interface disabled AND Network Interface still active at the same time, right?
EDIT: I’m pretty sure it’s because I have :: comments inside an IF block. Apparently that’s not cool with Windows batch scripting.
You are getting these errors because of the incorrect usage of IF ELSE structure. Using IF ELSE with brackets does not work in batch scripts as it would work in most programming languages.
The ELSE clause must occur on the same line as the command after the IF. Either move it onto the same line or use GOTO +labels.
Maybe it’s the “exit b” with the backslash? I think you mean “exit /b”. (Who knows, maybe it’s interpreting “b” as a path or something.)
I sometimes use the “::” as a comment character too. I don’t think that’s your problem.