You are not logged in.
Pages: 1
I have a code that outputs the contents of net use like so:
net use >> _%computername%_maps.txt
In this case the file is _CD0-PL0001_maps.txt
The output of the command is:
New connections will be remembered.
Status Local Remote Network
-------------------------------------------------------------------------------
OK R: \\nas-1\Marketing Production
Microsoft Windows Network
Unavailable S: \\192.168.1.5\Share1 Microsoft Windows Network
OK T: \\192.168.1.10\Downloads_CP
Microsoft Windows Network
OK U: \\192.168.1.50\Share1_TEST
Microsoft Windows Network
OK V: \\192.168.1.42\Share2
Microsoft Windows Network
OK W: \\192.168.1.3\Share7
Microsoft Windows Network
OK X: \\192.168.1.11\Share8 Microsoft Windows Network
OK Y: \\192.168.1.14\Share9
Microsoft Windows Network
OK Z: \\192.168.1.16\Share9
Microsoft Windows Network
The command completed successfully.
I have made the following script in order to interpret the data and mount every drive automatically. The idea here is to process the text file and automatically mount every folder with its original letter, while excluding all other useless data, especially those "Microsoft Windows Network" which are also listed in the output of the script.
@echo off
setlocal enabledelayedexpansion
for /f "skip=6 tokens=* delims= " %%a in ('type _CD0-PL0001_maps.txt') do (
@for /f "tokens=2 delims= " %%b in ('echo %%a') do set letter=%%b
@for /f "tokens=3 delims= " %%c in ('echo %%a') do set server=%%c
call :mountdrive !letter! !server!
)
:mountdrive
net use %1 %2
Thank you
Offline
No one? Come on guys. I just need a script to mount every drive share listed in the second snippet using the code from the third snippet.
Offline
I'm not seeing a question here; how does the code you've provided not already do what you're asking?
Last edited by Shadow Thief (30 Nov 2015 13:35)
Offline
The script loops through all lines of text. As you can see above, some lines contain only 'Microsoft Windows Network' and the script tries to mount this as well, and outputs an error. It should exclude those somehow.
Offline
Ah see from your wording, I thought you were just presenting your work, rather than soliciting advice.
There are a number of ways to skin this cat. Here's a slightly hacky one to try:
for /f "skip=6 tokens=* delims= " %%a in ('type _CD0-PL0001_maps.txt ^| find "\\"') do (
FYI - You may also experience issues if you have any mappings which aren't associated with drive letter. You could try this (in addition to the above):
:mountdrive
if /i "%~d1" NEQ "%~1" net use %1 & goto :EOF
net use %1 %2
Last edited by bluesxman (30 Nov 2015 14:52)
cmd | *sh | ruby | chef
Offline
It works but for some reason it only lists drives X: Y: and Z:.
I used the following to test:
:mountdrive
if /i "%~d1" NEQ "%~1" net use %1 & goto :eof
echo net use %1 %2
goto :eof
Offline
There were two parts to my post. The one you've mentioned was a side issue. Can you post the code you're running and the file you are processing?
cmd | *sh | ruby | chef
Offline
I used this with the example file from the first post:
pushd %~dp0
setlocal enabledelayedexpansion
for /f "skip=6 tokens=* delims= " %%a in ('type _CD0-PL0001_maps.txt ^| find "\\"') do (
@for /f "tokens=2 delims= " %%b in ('echo %%a') do set letter=%%b
@for /f "tokens=3 delims= " %%c in ('echo %%a') do set server=%%c
call :mountdrive !letter! !server!
)
:mountdrive
if /i "%~d1" NEQ "%~1" net use %1 & goto :eof
echo net use %1 %2
goto :eof
Last edited by Eehixohw (02 Dec 2015 07:36)
Offline
Sorry that was an error in my code, you need to remove the "skip=6". You're pre-filtering the net use list for UNC paths (find "\\") so the header messages are no longer in the output. Your "skip=6" will be jumping over mappings instead of the header.
Last edited by bluesxman (03 Dec 2015 11:53)
cmd | *sh | ruby | chef
Offline
Thank you.
Offline
Pages: 1