List hard drives on remote servers

R

Romain

Hi,

First of all, I'm sorry for many mistakes that I could write because I'm
French ...

So ! I have to list hard drives on remote servers (in a full Windows
environnment). A Perl script is running on only one server. With the
server hostname, I will give back these hard drives. In fact, I just
have to have drives letters. I try the Win32::NetAdmin::GetServerDisks()
function, but it returns *all* fixed drives, including floppy and cd-rom
drives. Floppy isn't really a problem, because I remove the "A:" letter,
but for the cd-rom, I don't know which letter it's represent.

Is a function that returns only hard drives exists ? And can it be used
remotely ?


Thanks for your help,


Best regards,


;-) Romain
(Once, sorry for my bad english...)
 
R

Reinhard Pagitsch

Hello Romain,
Hi,

First of all, I'm sorry for many mistakes that I could write because I'm
French ...
I am Austrian and I am sure that I make also many mistakes writing in
english :)
So ! I have to list hard drives on remote servers (in a full Windows
environnment). A Perl script is running on only one server. With the
server hostname, I will give back these hard drives. In fact, I just
have to have drives letters. I try the Win32::NetAdmin::GetServerDisks()
function, but it returns *all* fixed drives, including floppy and cd-rom
drives. Floppy isn't really a problem, because I remove the "A:" letter,
but for the cd-rom, I don't know which letter it's represent.

With the Win32::NetAdmin::GetServerDisks() function it is not possible
to get the drive type. I looked in the MS SDK for the function which
get the drives letters from a remote computer (NetServerDiskEnum), this
function is used by GetServerDisks(), and saw that it does not return
the types also.

But have you tryed the Win32::NetResource::NetShareGetInfo()? I am not
sure if it is possible to use this function for that what you want.


regards,
Reinhard
 
T

Thomas Kratz

Romain said:
Hi,

First of all, I'm sorry for many mistakes that I could write because I'm
French ...

So ! I have to list hard drives on remote servers (in a full Windows
environnment). A Perl script is running on only one server. With the
server hostname, I will give back these hard drives. In fact, I just
have to have drives letters. I try the Win32::NetAdmin::GetServerDisks()
function, but it returns *all* fixed drives, including floppy and cd-rom
drives. Floppy isn't really a problem, because I remove the "A:" letter,
but for the cd-rom, I don't know which letter it's represent.

Is a function that returns only hard drives exists ? And can it be used
remotely ?

Yup! Use WMI!

Here's a quick listing of the driveletters for harddisk partitions
(DriveType == 3)

use strict;
use warnings;

use Win32::OLE qw/in/;
Win32::OLE->Option(Warn => 1);

my $wmi = Win32::OLE->GetObject(
"winmgmts:{impersonationLevel=impersonate,(security)}"
# append '\\\\<machinename>' for remote access
) or die
"error initializing WMI interface, ",
Win32::OLE->LastError;

for my $ld ( in($wmi->InstancesOf('Win32_LogicalDisk')) ) {
next unless $ld->{DriveType} == 3;
print $ld->{DeviceID}, "\n"
}


If you need more information about the properties of the logical disk, get
the "WMI Object Browser" with the free "WMI Tools" from M$.

Thomas

--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
 

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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top