Batch file to show Network drives

J

joshboski

I am currently trying to write a batch file that will delete a list of
files from all of my network drives. The problem I am having is
getting the network drives. I am on a rather large network, and I
would like this to run on several different computers that may be
connected to different drives.
 
B

Bob I

See "net use" and "If exist" in Windows Help and support. Also there is
a cmd prompt group that has some pretty sharp folks(cross posting this)

news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin
 
J

joshboski

See "net use" and "If exist" in Windows Help and support. Also there is
a cmd prompt group that has some pretty sharp folks(cross posting this)

news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin

My apologies, that I did not include this also...I need the list of
local hard drives as well
 
P

Pegasus \(MVP\)

joshboski said:
My apologies, that I did not include this also...I need the list of
local hard drives as well

As Bob recommended: net use (for networked drives), and
mountvol | find ":\" for local drives.
 
P

Pegasus \(MVP\)

joshboski said:
My apologies, that I did not include this also...I need the list of
local hard drives as well

If you want something a little snazzier then you can use this script
file and massage it to give you the information you want. You need
to invoke it like so in your batch file: cscript //nologo c:\diskparms.vbs

Const Removable = 1
Const Fixed = 2
Const Network = 3
Const CDROM = 4
Const RAMDisk = 5

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set drives = oFSO.Drives

NewLine=Chr(10)
Line = ""

For Each drive In drives
Line = Line & "Drive " & drive.Path
Line = Line & " " & ShowDriveType(Drive)
If drive.IsReady Then Line = Line & ", ready" Else Line = Line & ", not
ready"

If drive.IsReady Then
If drive.DriveType=Network Then
Line = Line & ", Label=" & drive.ShareName
Else
Line = Line & ", Label=" & drive.VolumeName
End If

Line = Line & ", FS=" & drive.FileSystem
Line = Line & ", Total=" & Int(drive.TotalSize/1000000)
Line = Line & ", Free=" & Int(drive.FreeSpace/1000000)
Line = Line & ", Available=" & Int(drive.AvailableSpace/1000000)
Line = Line & ", Serial=" & Hex(drive.SerialNumber)
End If

Line = Line & NewLine
Next
wscript.echo Line

Function ShowDriveType(Drive)
Select Case drive.DriveType
Case Removable
T = "Removable"
Case Fixed
T = "Fixed"
Case Network
T = "Network"
Case CDROM
T = "CD-ROM"
Case RAMDisk
T = "RAM Disk"
Case Else
T = "Unknown"
End Select
ShowDriveType = T
End Function
 
D

Dean Wells \(MVP\)

Not as backwards compatible as some solutions offered here but,
nonetheless, worth a mention -

C:\>fsutil fsinfo drives

Drives: C:\ D:\ E:\ Z:\

.... iterating through that list and using -

C:\>fsutil fsinfo drivetype <insert drive letter here>

.... will return greater detail regarding the type of drive assignment.
 
P

Pegasus \(MVP\)

Dean Wells (MVP) said:
Not as backwards compatible as some solutions offered here but,
nonetheless, worth a mention -

C:\>fsutil fsinfo drives

Drives: C:\ D:\ E:\ Z:\

... iterating through that list and using -

C:\>fsutil fsinfo drivetype <insert drive letter here>

... will return greater detail regarding the type of drive assignment.

For reasons which I am unable to explain, Microsoft turned the
output of the command "fsutil fsinfo drives" into a set of $00-delimited
strings. The result is that I am unable to extract the individual
drive letters out of the string "Drives: C:\ D:\ E:\ F:\ Q:\ R:\",
using a batch file. Do you know of a way to do this?
 
D

Dean Wells \(MVP\)

Nod, I encountered the same limitation ... irritating isn't it.

Take a look at the 'bootSwitch.cmd' script here -

ftp://falcon.msetechnology.com/scripts/bootSwitch.cmd.txt

.... it contains a means of resolving this behavior by exploiting an
all-too-often useful unicode oddity. Other ways were and probably still
are available though; didn't give it much thought after I came it that
one.

As I'm sure you know, part of the enjoyment of solving these kind of
annoyances is the creativity involved in making such a limited
environment play nicely ... this is one of my favs. to date.
 
P

Pegasus \(MVP\)

Dean Wells (MVP) said:
Nod, I encountered the same limitation ... irritating isn't it.

Take a look at the 'bootSwitch.cmd' script here -

ftp://falcon.msetechnology.com/scripts/bootSwitch.cmd.txt

... it contains a means of resolving this behavior by exploiting an
all-too-often useful unicode oddity. Other ways were and probably still
are available though; didn't give it much thought after I came it that
one.

As I'm sure you know, part of the enjoyment of solving these kind of
annoyances is the creativity involved in making such a limited environment
play nicely ... this is one of my favs. to date.

Nicely done and highly imaginative but not my favourite.
I'm a great user of batch files but I wonder how long it
took you to get these lines just right and how maintainable
they are . . .
fsutil fsinfo drives >"%TEMP%\%~n0.$$$"
for /f "tokens=1 delims=\ skip=10" %%d in
('cmd /u /c type "%TEMP%\%~n0.$$$" ^| find /v ""') do echo %%d
 
E

Esra Sdrawkcab

Dean said:
Nod, I encountered the same limitation ... irritating isn't it.

Take a look at the 'bootSwitch.cmd' script here -

ftp://falcon.msetechnology.com/scripts/bootSwitch.cmd.txt

... it contains a means of resolving this behavior by exploiting an
all-too-often useful unicode oddity. Other ways were and probably still
are available though; didn't give it much thought after I came it that
one.

As I'm sure you know, part of the enjoyment of solving these kind of
annoyances is the creativity involved in making such a limited
environment play nicely ... this is one of my favs. to date.


Ritchie in 2003 (in alt.msdos.batch.nt) gave:


for /f "tokens=1,2" %%a in ('fsutil fsinfo drives^|more') do (
for /f "tokens=1" %%c in ('echo/%%b %%a') do fsutil fsinfo
drivetype %%c
)

terribly long google groups ref:

http://groups.google.com/group/alt....til+fsinfo+drives+batch&#doc_7ee6dafb8e2e38f5
 
D

Dean Wells \(MVP\)

I took a second look at that syntax and decided to try it, it didn't
work (on Vista at least.) C'est la vie ...

FWIW - my guess is that the OP is trying to handle the nuls in the same
manner but piping them through more vs. find. Since I can't fully test
it ... that's a bit of a hip-shot though.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


Dean Wells (MVP) said:
Assuming that works -- nice alternative.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


Esra Sdrawkcab said:
Ritchie in 2003 (in alt.msdos.batch.nt) gave:


for /f "tokens=1,2" %%a in ('fsutil fsinfo drives^|more') do (
for /f "tokens=1" %%c in ('echo/%%b %%a') do fsutil fsinfo
drivetype %%c
)

terribly long google groups ref:

http://groups.google.com/group/alt....til+fsinfo+drives+batch&#doc_7ee6dafb8e2e38f5
 
T

Timo Salmi

Pegasus (MVP) said:
This line works under WinXP:
fsutil fsinfo drives|more

One traditional, UNIX-flavored way of getting rid of nul characters in a
string is using a TR port

fsutil fsinfo drives|tr -d \000

Or SED
fsutil fsinfo drives|sed -e "s/\x00/ /g"

But indeed, fortunately, the more trick does the same as can be readily
seen with any hex lister. Also, as was recently discussed in another
connection, the more conveniently adds a 0D 0A pair at the end of the
output, if it is missing. Well, in this case it is not.

Not that fsutil fsinfo is the only way of listing ones active drives!
The code below will give a list of devices that are _ready_

@echo off & setlocal enableextensions enabledelayedexpansion
for %%d in (a: b: c: d: e: f: g: h: i: j: k: l: m: n:
o: p: q: r: s: t: u: v: w: x: y: z:) do (
dir %%d\ > nul 2>&1
if !errorlevel! EQU 0 echo %%d
)
endlocal & goto :EOF

E.g. one might get
C:\_D\TEST>cmdfaq
c:
d:
e:

All the best, Timo
 
T

Timo Salmi

Pegasus (MVP) said:
It appears that more.com under WinXP will translate Unicode to ASCII.

I doubted that it makes the suggested full conversion, so a little test.
You may wish to try

more TestFileInLatin1.txt > Outfile.txt

where Latin1 is ISO 8859-1, i.e. a Unicode 256 subset. The results do
not seem to comply.

All the best, Timo
 
H

Herb Martin

Bob I said:
See "net use" and "If exist" in Windows Help and support. Also there is a
cmd prompt group that has some pretty sharp folks(cross posting this)

news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin

I have been meaning to ask advice or figure the following out myself
so I will just post my solution and describe where it has problems.

The following code WORKS on Vista, but not on 2003, nor on
XP if I recall the latter correctly.

Following is all one line (in a batch file):

@for /f "tokens=1-26 delims=\ " %%a in ('fsutil fsinfo drives') do @for %%A
in (%%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n
%%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z) do @fsutil fsinfo drivetype
%%A


=======================
Ugly but it works on Vista like this:

A: - Remote/Network Drive
C: - Fixed Drive
D: - Fixed Drive
E: - Fixed Drive
F: - CD-ROM Drive
G: - CD-ROM Drive
H: - CD-ROM Drive
J: - Remote/Network Drive
O: - Remote/Network Drive
P: - Remote/Network Drive
Q: - Remote/Network Drive
R: - CD-ROM Drive
S: - Remote/Network Drive
T: - Remote/Network Drive
U: - Remote/Network Drive
W: - Remote/Network Drive
X: - Remote/Network Drive
Y: - Remote/Network Drive
Z: - Remote/Network Drive
 
H

Herb Martin

Ok, based on what someone (sorry) wrote in another message this
thread I finally figured out that XP/2003 were using NULLS instead
of spaces and so now my Perl version works on both all OSes:

Following is all one line for a batch file but works if pasted or typed in
directly:

@fsutil fsinfo drives | perl -n -e "@a=split /\s|\00/; foreach (@a) {next
unless s/\\//;print `fsutil fsinfo drivetype $_`;};"


OK, this works on 2003 using the | more trick (with +1 /S for efficiency):


@for /f %%a in ('fsutil fsinfo drives ^| more +1 /S') do @fsutil fsinfo
drivetype %%a


The MORE trick is problematic however if your command line is SMALLER
than the list of drives -- probably not a frequent issue but it will be an
issue
on rare occasions for some people.

I also admit that I cannot figure out Dean's unicode trick (quickly enough)
to extract and use it here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top