Hi Pat,

Thanks, the script works in creating a share on a remote system.  But I 
was not able to access the share on the remote machine because "File and 
Printer Sharing for Microsoft Networks" is disabled.  My original question 
was, is it possible to use WMI to enable "File and Printer Sharing for 
Microsoft Networks", on the remote machine, since WMI can query and do 
stuffs on the remote machine even if the above NetBIOS service is OFF.

Regards,
Sam Dela Cruz
Lotus Notes Support









"Patrick J. LoPresti" <[EMAIL PROTECTED]>
Sent by: 
[EMAIL PROTECTED]
09/30/2003 08:40 AM

 
        To:     Sam Dela Cruz/SVL/SC/[EMAIL PROTECTED]
        cc:     "Jim's Mail" <[EMAIL PROTECTED]>
[EMAIL PROTECTED]
        Subject:        Re: Is it possible to read a file remotely using WMI?
        Classification: 



[EMAIL PROTECTED] writes:

> Hi Jim,
> 
> I have written some script using WMI, but I don't exactly know how
> to enable file and printer sharing.  Do you have little snippets
> that I can use?  Thanks.

You are in luck; I feel like avoiding real work today.

Attached is a script which creates a network share on a local or
remote system.  For example, if you invoke it like this:

  share.pl --remote myhost C:\Perl perl

...it will export C:\Perl as a share named "perl" on myhost, so that
you can access it as \\myhost\perl.

It uses the Win32_Share class to work its magic; see
<http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_share.asp>.
To decipher the error status codes, follow the link for the "Create"
method.

 - Pat

use warnings;
use strict;
use Getopt::Long;
use Win32::OLE;

# Your usual option-processing sludge.
my %opts;
GetOptions (\%opts, 'remote=s')
    or die "Usage: $0 [--remote <host>] <path> <share>\n";

# Ensure exactly two arguments after options.
scalar @ARGV == 2
    or die "Usage: $0 [--remote <host>] <path> <share>\n";

my ($path, $share) = @ARGV;

# Bomb out completely if COM engine encounters any trouble.
Win32::OLE->Option ('Warn' => 3);

# Get a handle to the SWbemServices object of the machine.
my $computer = Win32::OLE->GetObject (exists $opts{'remote'}
                                      ? "WinMgmts://$opts{'remote'}/"
                                      : 'WinMgmts:');

# Get the Win32_Share class object.  See:
# <http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_share.asp>
my $share_class = $computer->Get ('Win32_Share');

my $ret = $share_class->Create ($path, $share, 0);

$ret == 0
    or die "Unable to share $path as $share; error $ret\n";

exit 0;



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

Reply via email to