List hard drives on remote servers

Discussion in 'Perl Misc' started by Romain, Mar 17, 2005.

  1. Romain

    Romain Guest

    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...)
     
    Romain, Mar 17, 2005
    #1
    1. Advertising

  2. Hello Romain,

    Romain wrote:

    > 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
     
    Reinhard Pagitsch, Mar 18, 2005
    #2
    1. Advertising

  3. Romain

    Thomas Kratz Guest

    Romain wrote:
    > 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^.-
     
    Thomas Kratz, Mar 18, 2005
    #3
  4. Romain

    Romain Guest

    Thanks for your help ! It works fine ...

    ;-) Romain.


    Thomas Kratz <> wrote in message news:<423ab534$0$18082$-rheiner.de>...
    > Romain wrote:
    > > 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
     
    Romain, Mar 21, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UHJhZGVlcCBTdW5kYXJhbShNU0ZUKQ==?=

    Enumerate all the drives including Mapped network drives on a serv

    =?Utf-8?B?UHJhZGVlcCBTdW5kYXJhbShNU0ZUKQ==?=, Feb 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,038
    =?Utf-8?B?UHJhZGVlcCBTdW5kYXJhbShNU0ZUKQ==?=
    Feb 26, 2005
  2. Chris
    Replies:
    2
    Views:
    428
    Boudewijn Dijkstra
    Jan 8, 2005
  3. RunLevelZero
    Replies:
    4
    Views:
    473
    Mike Meyer
    Jun 5, 2005
  4. =?iso-8859-1?q?S=E9bastien_de_Mapias?=

    Accessing raw devices (hard drives) with Java ?

    =?iso-8859-1?q?S=E9bastien_de_Mapias?=, Sep 10, 2007, in forum: Java
    Replies:
    10
    Views:
    2,272
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Sep 15, 2007
  5. Gary Chan

    Enumerate all the remote drives

    Gary Chan, Aug 9, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    132
    Jay Tilton
    Aug 10, 2003
Loading...

Share This Page