Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re^11: Lanman Netshare by bulk88
in thread Lanman Netshare by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [Corion]: hippo: At least for the German translation, the wordplay is translated as well
    [Discipulus]: always! but if i can ask choroba why you always use the inverted (to me) form 1 == $.?
    [choroba]: To avoid accidental overwriting of the variable in if ($x = 3)
    [karlgoethebier]: Corion: Auch in hessisch? Mer wasses net.
    [Corion]: Hmm - I'm not sure, I haven't read the mundart/slang translations ;)
    [Eily]: $F[1] =~ s/^0//r could be written as (0+$F[1]). It's less explicit though
    [Discipulus]: ah! seems wise choroba, you play safe
    [shmem]: Eily: also -+-$F[1]

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (11)
    As of 2017-05-24 08:42 GMT
    Find Nodes?
      Voting Booth?