简体   繁体   English

批处理IF IP地址为192.168.1。

[英]Batch IF IP address is 192.168.1.“” then

I want to create a batch file to map drives dependent on the location where the user logs in. I created some batch files, but they are not working properly. 我想创建一个批处理文件来映射驱动器,具体取决于用户登录的位置。我创建了一些批处理文件,但是它们无法正常工作。 The user only gets the mapped drives from the first location, no matter where they log in. Only the batch file with the menu is working, I want it to automatically update. 用户无论从何处登录,都只能从第一个位置获取映射的驱动器。只有带有菜单的批处理文件正在运行,我希望它自动更新。 Here are the batch files. 这是批处理文件。 Hopefully you could help me. 希望你能帮助我。

@ECHO OFF
ipconfig    | find /i "192.168.1." > NUL
IF ERRORLEVEL == 0 GOTO Server1
ipconfig    | find /i "192.168.2." > NUL
IF ERRORLEVEL == 0 GOTO Server2
ECHO Ip adres conflict
PAUSE
GOTO END
:Server1
net use H: \\Server1\Users$\%username%
net use S: \\Server1\Folder
GOTO END
:Server2
net use H: \\Server2\Users$\%username%
net use S: \\Server2\Folder
GOTO END
:END


@ECHO OFF
ipconfig | find /c "192.168.1."> NUL2>NUL
IF ERRORLEVEL==0 GOTO Server1
ipconfig | find /c "192.168.2."> NUL2>NUL
IF ERRORLEVEL==0 GOTO Server2
ECHO Ip adres conflict
PAUSE
GOTO END
:Server1
net use H: \\Server1\Users$\%username%
net use S: \\Server1\Folder
GOTO END
:zwaluwhoeve
net use H: \\Server2\Users$\%username%
net use S: \\Server2\Folder
GOTO END
:END

The problem is that this code is not working. 问题是此代码无法正常工作。 It only maps the drives from one location. 它仅从一个位置映射驱动器。 Hopefully you can help me. 希望你能帮助我。 PS: sorry for the bad english. PS:对不起,英语不好。

You can't access the error level with ERRORLEVEL but with %ERRORLEVEL% ! 您无法使用ERRORLEVEL而是使用%ERRORLEVEL%来访问错误级别! In your code you are comparing the string ERRORLEVEL with 0 . 在您的代码中,您将字符串ERRORLEVEL0进行比较。 This is obviously always false. 这显然总是错误的。 Adding % should work. 添加%应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM