Question : EnumNetworkDrives Method in batch script

hey,

is there any way to check above in a batch file ?
my idea was to play with net use, but how can i capture specific drive UNC ?

one last thing after i got the unc how can i play with the parts ?
what i mean for example :

\\serverA\public

how to "pull" serverA and lets say ping it ?
or check if the folder name it's public and if not remap another folder ?

if i asking to much in one question just say :-)

thanks

Answer : EnumNetworkDrives Method in batch script

That makes sense. But do your folks need to use persistent network drives? It would make things easier if drive mappings wouldn't survive a reboot.

Having said that, let's make a first attempt.
It's not easy to decide the subnet thing - how should that work? Should it be a decision based
  1. on IP address  -  dangerous if you use subnet masks differing from Classes A,B,C, or different subnet masks in the branches, 
  2. or DNS names - difficult, as the full qualified name might not appear in net use, and a DNS query will not help. 
The following snippet is based on
  • each server is reachable via ping
     
  • we are using Class C only
     
It does not matter if a drive mapping or only UNC is used. The net use /d is only echoed, for test reasons. You can remove the echo (word only) to execute it.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
@echo off
setlocal EnableDelayedExpansion
 
REM Assuming Class C, 192.168.x.y => net 192.168.x
for /F "tokens=2 delims=[]" %%C in ('ping -n 1 %computername% ^| find "["') do set net=%%~nC
 
for /F "tokens=2-4 delims=\ " %%S in ('net use ^| find "\"') do (
  set srv=%%S
  if "!srv:~1,1!" == ":" (
    set srv=%%T
    set share=%%S  
  ) else (
    set share=\\%%S\%%T
  )
  for /F "tokens=2 delims=[]" %%C in ('ping -n 1 !srv! ^| find "["') do (
    if not %net% == %%~nC echo net use !share! /d
  )
)
Open in New Window Select All
Random Solutions  
 
programming4us programming4us