Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

by gods
on Feb 11, 2000 at 00:06 UTC ( #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);
Output
$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

Title:
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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (8)
    As of 2016-08-30 15:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The best thing I ever won in a lottery was:















      Results (419 votes). Check out past polls.