Parsing 在Windows 7中,识别映射驱动器的ip并重新连接

Parsing 在Windows 7中,识别映射驱动器的ip并重新连接,parsing,windows-7,command-prompt,windows-7-x64,network-drive,Parsing,Windows 7,Command Prompt,Windows 7 X64,Network Drive,我知道我可以在windows 7中使用 c:\>网络使用 它表明 Status Local Remote Network ------------------------------------------------------------------------------- OK X: \\192.168.168.100\c\Output

我知道我可以在windows 7中使用

c:\>网络使用

它表明

Status       Local     Remote                    Network
-------------------------------------------------------------------------------
OK           X:        \\192.168.168.100\c\Output
                                            Microsoft Windows Network
OK           Y:        \\192.168.168.100\c\Input
                                            Microsoft Windows Network
是否有可能发现X(或Y)是否连接到ip 192.168.168.100? 在这种情况下,使用

net use X: /delete
net use Y: /delete
并使用(从192.168.168.100到192.168.168.101)将它们重新连接到同一路径但不同的ip

反之亦然,如果它们连接到192.168.168.101,则断开并重新连接 至192.168.168.100


有人能帮我解析net use输出吗?

不太好,但它在我有限的测试中有效:

@echo OFF
setlocal ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
goto start

:checkone
setlocal
echo INFO: %3 is mapped to drive %2
set "server="&set "new="
for /F "usebackq tokens=1,* delims=\" %%A in ('%3') do @set server=%%A&set share=%%B
if "%server%"=="192.168.168.100" set new=192.168.168.101
if "%server%"=="192.168.168.101" set new=192.168.168.100
if not ".%new%"=="." (
    call net use %2 /delete
    call net use %2 \\%new%\%share% /user:user01
)
endlocal
@goto :EOF

:start
for /F "tokens=*" %%A in ('net use^|find ":"^|find "\\"') do @for /F "usebackq tokens=1,* delims=:" %%B in ('.%%A') do call :checkone %%B: %%C

如果远程路径有空格,可能会出现问题…

看起来您已经解决了。您具体需要什么帮助?我不知道如何在.bat中识别映射的驱动器是否指向192.168.168.100或192.168.168.101,然后按照您看到的那样操作,您可以使用
net use
命令解析输出。有人可以帮我解析net use输出吗?您可以使用
for
命令解析命令的输出。键入
以获取/?
以获取详细信息。
@echo OFF
setlocal ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
goto start

:checkone
setlocal
echo INFO: %3 is mapped to drive %2
set "server="&set "new="
for /F "usebackq tokens=1,* delims=\" %%A in ('%3') do @set server=%%A&set share=%%B
if "%server%"=="192.168.168.100" set new=192.168.168.101
if "%server%"=="192.168.168.101" set new=192.168.168.100
if not ".%new%"=="." (
    call net use %2 /delete
    call net use %2 \\%new%\%share% /user:user01
)
endlocal
@goto :EOF

:start
for /F "tokens=*" %%A in ('net use^|find ":"^|find "\\"') do @for /F "usebackq tokens=1,* delims=:" %%B in ('.%%A') do call :checkone %%B: %%C