Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

trouble with Win32::NetResource

by thealienz1 (Pilgrim)
on Oct 08, 2001 at 23:51 UTC ( #117537=perlquestion: print w/replies, xml ) Need Help??

thealienz1 has asked for the wisdom of the Perl Monks concerning the following question:

Alright when I run the following code:

# # This example displays all the share points in the entire # visible part of the network. # use strict; use Win32::NetResource; qw(:DEFAULT GetSharedResources GetError); my $resources = []; unless(GetSharedResources($resources, RESOURCETYPE_ANY)) { my $err = undef; GetError($err); warn Win32::FormatMessage($err); } foreach my $href (@$resources) { next if ($$href{DisplayType} != RESOURCEDISPLAYTYPE_SHARE); print "-----\n"; foreach( keys %$href){ print "$_: $href->{$_}\n"; } }

I get the following error and I cannot figure why this is happening... I am guessing windows, but it doesn't seem to be the problem.

Can't load 'C:/Perl/site/lib/auto/Win32/NetResource/NetResource.dll' f +or module Win32::NetResource: load_file:A device attached to the system is not f +unctioning at C:/Perl/lib/ line 206. at line 6 Compilation failed in require at line 6. BEGIN failed--compilation aborted at line 6.

My goal is to write a program that scans an entire Windows Network Neighborhood for files and displays them. So, far I have had a rocky start. if anyone has anything to say about my project I welcome any thoughts.

Thanks in advance... jtarchie

Replies are listed 'Best First'.
Re: trouble with Win32::NetResource
by RayRay459 (Pilgrim) on Oct 09, 2001 at 02:19 UTC
    what version of perl are you running? How did you install the module. PPM is the best way to get modules installed. If you want a cludge way to do this, you could always do
    open(NETVIEW, "net view|") or die "$!"; print NETVIEW;
    Here's some code that i found while doing a search on netResource:
    use Win32::Lanman; $odir = "C:\\TEMP\\SHARES"; if (!-e "$odir"){mkdir ($odir, 0777)|| die "Unable to create $odir";} %stype = (1,'Printer',-2147483648,'Default',0,'File', -2147483645, 'InterProcess Communication'); @servers = &getservers; foreach (@servers) { unless(Win32::Lanman::NetShareEnum("\\\\$_", \@shares)){next;} $output = ("$odir\\$_.txt"); open(OUTFILE, ">$output") || die ("cannot open output file ", $output +, "\n"); foreach $share (@shares) { print OUTFILE "Server = $_\n"; print OUTFILE "Name = ${$share}{'netname'}\n"; print OUTFILE "Type = $stype{${$share}{'type'}}"; $lc = chop ${$share}{'netname'}; if ($lc eq "\$"){print OUTFILE " (hidden)\n";}else{print OUTFILE "\n +"} print OUTFILE "Path = ${$share}{'path'}\n"; print OUTFILE "Remarks = ${$share}{'remark'}\n\n"; } close OUTFILE; } sub getservers { unless(my $domain = Win32::DomainName){print "Unable to obtain the do +main name.";} my ($PDC, $domain, @servers1, @S1, @S2); unless($domain = Win32::DomainName){print "Unable to obtain the domai +n name.";} foreach (SV_TYPE_DOMAIN_CTRL, SV_TYPE_DOMAIN_BAKCTRL, SV_TYPE_SERVER_ +NT) { unless(Win32::Lanman::NetServerEnum( '', $domain, $_, \@S1)){print " +Unable to obtain information on $_ .";} foreach (@S1){push( @S2, ${$_}{'name'})} push(@servers1, sort @S2); undef @S2; } undef ($domain, $PDC); undef @S1; return(@servers1); # Returns the server list }
Re: trouble with Win32::NetResource
by Rex(Wrecks) (Curate) on Oct 09, 2001 at 00:16 UTC
    Basics first, looks like 'C:/Perl/site/lib/auto/Win32/NetResource/NetResource.dll' is either not on the system or corrupted in some way.

    How did you install the module? did you actually look to see if the file was there? Mabey try replacing that file from the archive you installed from. Looks like DynaLoader doesn't like that file and can't load it.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: trouble with Win32::NetResource
by seigniory (Sexton) on Oct 09, 2001 at 00:57 UTC
    You can always just use

    my $networkNeighborhood = `net view`;

    and be done with it.
Re: trouble with Win32::NetResource
by $code or die (Deacon) on Oct 09, 2001 at 05:34 UTC
    That looks like the example from the documenation, so there shouldn't be any problems with the code.

    On the other hand, you have an extra semi-colon in the line:
    use Win32::NetResource; qw(:DEFAULT GetSharedResources GetError);
    That should read:
    use Win32::NetResource qw(:DEFAULT GetSharedResources GetError);
    I don't think that is your problem though. I think you should try and reinstall Win32::NetResource - but because it is part of libwin32 and installed by default in ActivePerl, ActiveState may not provide a PPM. So if you can't upgrade (ppm verify --upgrade libwin32/Win32-NetResource), then you might want to try reinstalling perl.

    I can't test the code at the moment - no Win32 at home. Good luck

    And I don't think "net view" is the answer - the net command is nasty and a lot more work than getting Win32::NetResource working. And as already mentioned, Win32::Lanman is a nice alternative.

    Simon Flack ($code or die)
    $,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
    =~y'_"' ';eval"die";print $_,lc substr$@,0,3;
Re: trouble with Win32::NetResource
by thealienz1 (Pilgrim) on Oct 09, 2001 at 06:44 UTC

    Yes, but unfortunetly I am not running a WinNT machine, so Lanman does not work on WinME or 9x system. Are there any other alternatives?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://117537]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2020-09-19 16:07 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (114 votes). Check out past polls.