Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^8: Lanman Netshare

by VinsWorldcom (Parson)
on Oct 01, 2012 at 10:52 UTC ( #996617=note: print w/replies, xml ) Need Help??

in reply to Re^7: Lanman Netshare
in thread Lanman Netshare

Then use:

net view \\

Replies are listed 'Best First'.
Re^9: Lanman Netshare
by Anonymous Monk on Oct 01, 2012 at 11:39 UTC

    But is'nt there any module in perl which can help in checking connection to a share? The net view command gives me a lot of information about the share which i do not want ..

        Here you go. Tested on 32 bit Windows. Should work on x64 but untested.
        use Data::Dumper; use Win32::API 0.71 qw( SafeReadWideCString ); use Encode; use Carp; use Config; BEGIN{ sub NERR_Success () { 0 } sub MAX_PREFERRED_LENGTH () { 0xFFFFFFFF } eval ' sub POINTER () { "' .($Config{ptrsize} == 8 ? 'Q' : 'L'). '" }'; } sub NetStatusOK { if($_[0] != NERR_Success){ $Carp::CarpLevel = 1; croak("NETAPI call failed with $_[0]"); } return $_[0]; } Win32::API::Type->typedef('NET_API_STATUS' , 'DWORD'); my $NetShareEnum = Win32::API::More->new('Netapi32.dll', 'NET_API_STAT +US NetShareEnum( LPWSTR servername, DWORD level, LPHANDLE bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries, LPDWORD resume_handle )'); die "NetShareEnum couldn't be created: $^E" if !$NetShareEnum; { my $NetApiBufferFree = Win32::API::More->new('Netapi32.dll', 'NET_API_STATUS NetApiBufferFree(HANDLE Bu +ffer)'); die "NetApiBufferFree couldn't be created: $^E" if !$NetApiBufferF +ree; sub NetApiBufferFree { NetStatusOK($NetApiBufferFree->Call($_[0])); } } my($bufferptr, $entriesread, $totalentries) = (0,0,0); NetStatusOK($NetShareEnum->Call(Encode::encode('UTF-16LE','\\\\127.0.0 +.1'."\x00"), 1, $bufferptr, MAX_PREFERRED_LENGTH, $entriesread, $totalentries, undef)); die "no entries from NetShareEnum " if ! $entriesread; my @PACKED_SHARE_INFO_1 = unpack('(a['.POINTER.'Lx!['.POINTER.']'.POIN +TER.'])['.$entriesread.']', unpack('P[('.POINTER.'Lx!['.POINTER.']'.PO +INTER.')['.$entriesread.']]', pack(POINTER, $bufferptr))); my @SHARE_INFO; for(@PACKED_SHARE_INFO_1){ my %SHARE_INFO_1; ($SHARE_INFO_1{'shi1_netname'}, $SHARE_INFO_1{'shi1_type'}, $SHARE +_INFO_1{'shi1_remark'}) = unpack(POINTER.'Lx!['.POINTER.']'.POINTER, $_); $SHARE_INFO_1{'shi1_netname'} = SafeReadWideCString($SHARE_INFO_1{ +'shi1_netname'}); $SHARE_INFO_1{'shi1_remark'} = SafeReadWideCString($SHARE_INFO_1{' +shi1_remark'}); push(@SHARE_INFO, \%SHARE_INFO_1); } NetApiBufferFree($bufferptr); print Dumper([$buffer, $bufferptr, $entriesread, $totalentries]); print Dumper(\@SHARE_INFO);
        $VAR1 = [ undef, 1420904, 4, 4 ]; $VAR1 = [ { "shi1_type" => "2147483651", "shi1_remark" => "Remote IPC", "shi1_netname" => "IPC\$" }, { "shi1_type" => 0, "shi1_remark" => "C", "shi1_netname" => "C" }, { "shi1_type" => "2147483648", "shi1_remark" => "Remote Admin", "shi1_netname" => "ADMIN\$" }, { "shi1_type" => "2147483648", "shi1_remark" => "Default share", "shi1_netname" => "C\$" } ];
        This code does exactly what "net view" does BTW.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996617]
[Lady_Aleena]: Right now, I'm trying to decide whether I want to rewrite how variables are entered in the sub I'm working on.
[shmem]: wait, what? you want that person to read the documentation for you?
[Lady_Aleena]: I might have to go with options instead of a straight list.
[Discipulus]: if more than 3 go for named variables LA
[Lady_Aleena]: Discipulus, it is at 2 now, but with what I am thinking about, it could go to 3. However, only 1 is needed. The second and third are optional.
[shmem]: straight list or named parameters - that depends on whether (and how many) optional arguments you have
[Discipulus]: if so a plain list is ok, imho
[Lady_Aleena]: shmem, I already have the plugin installed, just not active.
[shmem]: if you have 1 optional argument, place that at the end of the list. If you have more, go for named parameters.
[Lady_Aleena]: 1 manditory, 2 optional.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2017-04-27 12:19 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (506 votes). Check out past polls.