in reply to Trying to get drive space info on remote Windows servers

It looks like the backslash before your dollar sign is causing the problem; being in single-quotes, there's nothing special about the dollar sign, so the resulting string is:

\\server01\c\$

instead of the more-likely-in-a-windows-environment:

\\server01\c$

Replies are listed 'Best First'.
Re^2: Trying to get drive space info on remote Windows servers
by Cloudster (Novice) on Feb 18, 2010 at 18:13 UTC
    Still no joy. Here's the current code:
    use Win32::DriveInfo; use constant { SECTORS_PER_CLUSTER => 0, BYTES_PER_SECTOR => 1, FREE_CLUSTERS => 2, TOTAL_CLUSTERS => 3, BYTES_FREE_4_CALLER => 4, TOTAL_BYTES => 5, TOTAL_FREE => 6, }; #$sql = "\\\\server01\\d\$"; $sql = "c:"; print "$sql\n"; print "Drive Free Tot PctFree\n"; my @info = Win32::DriveInfo::DriveSpace($sql) or die "DriveSpace failed with error: $^E"; printf "%.3f GB free of total %.3f GB\n", $info[ TOTAL_FREE ] / 1024**3, $info[ TOTAL_BYTES ] / 1024**3;
    If I run it against the server specified in the line that's commented out, it returns zeroes and no error. If I run it against my C:, it returns accurate numbers. So I don't think it's going out to the network, yet it isn't returning an error.

    Here's the output of two runs:
    c:\Perl>drivelist.pl \\server01\d$ Drive Free Tot PctFree 0.000 GB free of total 0.000 GB c:\Perl>drivelist.pl c: Drive Free Tot PctFree 31.639 GB free of total 74.444 GB

      Try printing $^E unconditionally, immediately after call. It might show an error that the module is failing to act upon.

        The thought plickens!

        Here's the latest generation of the code:
        use Win32::DriveInfo; use constant { SECTORS_PER_CLUSTER => 0, BYTES_PER_SECTOR => 1, FREE_CLUSTERS => 2, TOTAL_CLUSTERS => 3, BYTES_FREE_4_CALLER => 4, TOTAL_BYTES => 5, TOTAL_FREE => 6, }; #$sql = "\\\\server01\\d\$"; $sql = "c:"; print "$sql\n"; print "Drive Free Tot PctFree\n"; my @info = Win32::DriveInfo::DriveSpace($sql) ; print "$^E\n"; # or die "DriveSpace failed with error: $^E"; printf "%.3f GB free of total %.3f GB\n", $info[ TOTAL_FREE ] / 1000**3, $info[ TOTAL_BYTES ] / 1000**3;
        And here's the output of two runs:
        c:\Perl>drivelist.pl \\sql-01\d$ Drive Free Tot PctFree 0.000 GB free of total 0.000 GB c:\Perl>drivelist.pl c: Drive Free Tot PctFree The specified procedure could not be found 31.283 GB free of total 74.444 GB c:\Perl>dir Volume in drive C is cMore Volume Serial Number is A07E-ED9D Directory of c:\Perl 02/18/2010 10:59 PM <DIR> . 02/18/2010 10:59 PM <DIR> .. 05/30/2008 03:51 PM <DIR> bin 05/30/2008 03:51 PM <DIR> eg 05/30/2008 03:51 PM <DIR> etc 05/30/2008 03:52 PM <DIR> html 05/30/2008 03:51 PM <DIR> lib 05/30/2008 03:51 PM <DIR> man 05/30/2008 03:51 PM <DIR> site 02/18/2010 10:58 PM 629 drivelist.bak 02/18/2010 10:59 PM 628 drivelist.pl 2 File(s) 1,257 bytes 9 Dir(s) 33,590,083,584 bytes free
        So if I point it to my local drive, I get an error condition but I get correct results. If I point it to a server $root share, I get no results but nothing in the error string. And I tried running it against my local machine as a \\pcname\c$ and got the same result as a remote server, zeroes for space and no error.

        I noticed the discrepency on disk space. Turns out I need to divide by 1000**3 rather than 1024**3. Easy fix there. I have a couple of thoughts that I'll try tomorrow when I'm in the office.

        I should have mentioned the Perl version that I'm running is:
        c:\Perl>perl -v This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 5 registered patches, see perl -V for more detail) Copyright 1987-2007, Larry Wall Binary build 1003 [285500] provided by ActiveState http://www.ActiveSt +ate.com Built May 13 2008 16:52:49
        I should probably look at an update tomorrow, but I don't think that's the issue. My PC is XP Pro SP3. I'm logged on as a general user but running a command prompt session as my network admin login, so if I do a 'dir \\server01\d$', I see results just fine.

      Strange; works fine here with all drives/shares I have access to.

      I don't know if it would a prove useful diagnostic, but have you tried checking your C: drive via \\yourpc\c$ instead of c:?