"David Rigaudiere" <[EMAIL PROTECTED]> writes:
> Hello,
> i'm looking for a module for lists currently mapped drive,
> like NET USE but i don't want spawn a process.
>
> I have to know F: => \\server1\share, G: => \\goo\bar ...
>
> My first idea was to look at Win32::Lanman, there is functions
> to manipulate shares, but not mapped drive, or i'm wrong ?
>
> I can't use WMI, some of workstations are NT4 without WMICore
> installed.
>
> Any idea ?
Are you *sure* you do not want simply to install WMI?
use warnings;
use strict;
use Win32::OLE;
# Bomb out completely if COM engine encounters any trouble.
Win32::OLE->Option ('Warn' => 3);
my $computer = Win32::OLE->GetObject ('WinMgmts:');
# See <http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_logicaldisk.asp>
my $drives_set = $computer->ExecQuery
('SELECT * FROM Win32_LogicalDisk WHERE DriveType = 4');
# Convert set to Perl array.
my @drives = Win32::OLE::Enum->All ($drives_set);
foreach my $drive (@drives) {
print "$drive->{'Name'} is mapped to $drive->{'ProviderName'}\n";
}
So clean :-).
Well, you can use WSH instead:
use warnings;
use strict;
use Win32::OLE;
# Bomb out completely if COM engine encounters any trouble.
Win32::OLE->Option ('Warn' => 3);
# Get WshNetwork object. See
# <http://msdn.microsoft.com/library/en-us/script56/html/wsobjwshnetwork.asp>
my $wsh_network = Win32::OLE->CreateObject ('WScript.Network');
# <http://msdn.microsoft.com/archive/en-us/wsh/htm/wsMthEnumNetworkDrives.asp>
my $drives_set = $wsh_network->EnumNetworkDrives ();
my @drives = Win32::OLE::Enum->All ($drives_set);
while (scalar @drives > 0) {
my $drive = shift @drives;
my $path = shift @drives;
print "$drive is mapped to $path\n";
}
I have not tried it on NT, but it should work. I think.
- Pat