> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of David Rigaudiere
> Sent: Friday, December 05, 2003 10:24 AM
> To: [EMAIL PROTECTED]
> Subject: "NET USE" without spawn a process 
> 
> 
> 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 ?
> 
> David "Sniper" Rigaudiere
> Core member of Paris Perl Mongers
>  
>

You need Win32::FileOp.  It does all that.
You can get it from Jenda's page here: http://jenda.krynicky.cz/
You might even be able to PPM it... I don't remember if I got it that
way or not.

Here are some of its functions and stuff:
Map
         Map $drive => $share;
         $drive = Map $share;
         Map $drive => $share, \%options;
         $drive = Map $share, \%options;
        Map a drive letter or LTPx to a network resource. If successfull
returns the drive letter/LPTx.
        If you do not specify the drive letter, the function uses the
last free letter, if you specify undef or empty string as the drive then
the share is connected, but not assigned a letter.
        Since the function doesn't require the ':' in the drive name you
may use the function like this:
         Map H => '\\\\server\share';
         as well as
         Map 'H:' => '\\\\server\share';
         Options:
          persistent => 0/1
                  should the connection be restored on next logon?
          user => $username
                  username to be used to connect the device
          passwd => $password
                  password to be used to connect the device
          overwrite => 0/1
                  should the drive be remapped if it was already
connected?
          force_overwrite => 0/1
                  should the drive be forcefully disconnected and
                  remapped if it was already connected?
          interactive = 0 / 'yes' / $WindowHandle
                  if necessary displays a dialog box asking the user
                  for the username and password.
          prompt = 0/1
                  if used with interactive=> the user is ALWAYS asked
for the username
                  and password, even if you supplied them in the call.
If you did not specify
                  interactive=> then prompt=> is ignored.
          redirect = 0/1
                  forces the redirection of a local device when making
the connection
         Example:
          Map I => '\\\\servername\share', {persistent=>1,overwrite=>1};
        Notes: 1) If you use the interactive option the user may Cancel
that dialog. In that case the Map() <>  fails, returns undef and
Win32::GetLastError() returns 1223 and $^E is equals to 1223 in
numerical context and to ``The operation was canceled by the user.'' in
string context.
        2) You should only check the Win32::GetLastError() or $^E if the
function failed. If you do check it even if it succeeded you may get
error 997 ``Overlapped I/O operation is in progress.''. This means that
it worked all right and you should not care about this bug!
        REM: Based on Win32 API function WNetAddConnection3().
Connect
                Connect $share
                Connect $share, \%options
        Connects a share without assigning a drive letter to it.
        REM: Based on Win32 API function WNetAddConnection3().
Disconnect
         Disconnect $drive_or_share;
         Disconnect $drive_or_share, \%options;
        Breaks an existing network connection. It can also be used to
remove remembered network connections that are not currently connected.
        $drive_or_share specifies the name of either the redirected
local device or the remote network resource to disconnect from. If this
parameter specifies a redirected local resource, only the specified
redirection is broken; otherwise, all connections to the remote network
resource are broken.
         Options:
          persistent = 0/1, if you do not use persistent=>1, the
connection will be closed, but
                       the drive letter will still be mapped to the
device
          force      = 0/1, disconnect even if there are some open files
         See also: Unmap
        REM: Based on Win32 API function WNetCancelConnection2().
Unmap
         Unmap $drive_or_share;
         Unmap $drive_or_share, \%options;
        The only difference from Disconnect is that persistent=>1 is the
default.
        REM: Based on Win32 API function WNetCancelConnection2().
Mapped
         %drives = Mapped;
         $share = Mapped $drive;
         $drive = Mapped $share; # currently not implemented !!!
        This function retrieves the name of the network resource
associated with a local device. Or vice versa.
        If you do not specify any parameter, you get a hash of drives
and shares.
        To get the error message from most of these functions, you
should not use $!, but Win32::FormatMessage(Win32::GetLastError()) or
$^E !
        REM: Based on Win32 API function WNetGetConnection().
Subst
         Subst Z => 'c:\temp';
         Subst 'Z:' => '\\\\servername\share\subdir';
        This function substitutes a drive letter for a directory, both
local and UNC.
        Be very carefull with this, cause it'll allow you to change the
substitution even for C:. ! Which will most likely be lethal !
        Works only on WinNT.
        REM: Based on DefineDosDevice()
         =item SubstDev
         SubstDev F => 'Floppy0';
         SubstDev G => 'Harddisk0\Partition1';
        Allows you to make a substitution to devices. For example if you
want to make an alias for A: ...
        To get the device mapped to a drive letter use Substed() <>  in
list context.
        Works only on WinNT.
        REM: Based on DefineDosDevice()
Unsubst
         Unsubst 'X';
        Deletes the substitution for a drive letter. Again, be very
carefull with this!
        Works only on WinNT.
        REM: Based on DefineDosDevice()
Substed
         %drives = Substed;
         $substitution = Substed $drive;
         ($substitution, $device) = Substed $drive;
        This function retrieves the name of the resource(s) associated
with a drive letter(s).
        If used with a parameter :
        In scalar context you get the substitution. If the drive is the
root of a local device you'll get an empty string, if it's not mapped to
anything you'll get undef.
        In list context you'll get both the substitution and the
device/type of device :
         Substed 'A:' => ('','Floppy0')
         Substed 'B:' => undef
         Substed 'C:' => ('','Harddisk0\Partition1')
         Substed 'H:' => ('\\\\servername\homes\username','UNC')
          # set by subst H: \\servername\homes\username
         Substed 'S:' => ('\\\\servername\servis','LanmanRedirector')
          # set by net use S: \\servername\servis
         Substed 'X:' => ()
          # not mapped to anything
        If used without a parameter gives you a hash of drives and their
corresponding sunstitutions.
        Works only on WinNT.
        REM: Based on Win32 API function QueryDosDevice().


_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to