Re: Detecting shares using walk_dir()

new topic     » goto parent     » topic index » view thread      » older message » newer message
jimcbrown said...

Not sure this helps .. the OP wants to get the list of shares on a machine, not look inside a specific share. Something akin to "smbclient -L machine" IIUC.

Yeah, I kind of overshot that one, didn't I? I saw the mis-escaped backslashes and figured that was his problem. getlost

I believe the trick here is to use WNetEnumResource. Here is a wrapper for the necessary API functions to get started. I will actually wrap them into a better "enumerate shares" function if I have time later.

Also, I should point out that walk_dir() and other functions do not work here, because the resource \\some-server is not a directory. It is a "container" and the shares inside may point to either a disk or a printer. So we're concerned about enumerating the disk shares, which we can then inspect with walk_dir(), etc.

-- file: mpr.e 
include std/dll.e 
include std/machine.e 
include std/math.e 
 
public constant 
    RESOURCE_CONNECTED  = 1, 
    RESOURCE_GLOBALNET  = 2, 
    RESOURCE_REMEMBERED = 3, 
    RESOURCE_RECENT     = 4, 
    RESOURCE_CONTEXT    = 5, 
$ 
 
public constant 
    RESOURCETYPE_ANY        = 0, 
    RESOURCETYPE_DISK       = 1, 
    RESOURCETYPE_PRINT      = 2, 
    RESOURCETYPE_RESERVED   = 8, 
    RESOURCETYPE_UNKNOWN    = #FFFFFFFF, 
$ 
 
public constant 
    RESOURCEUSAGE_CONNECTABLE   = #00000001, 
    RESOURCEUSAGE_CONTAINER     = #00000002, 
    RESOURCEUSAGE_NOLOCALDEVICE = #00000004, 
    RESOURCEUSAGE_SIBLING       = #00000008, 
    RESOURCEUSAGE_ATTACHED      = #00000010, 
    RESOURCEUSAGE_ALL           = or_all({ RESOURCEUSAGE_CONNECTABLE, RESOURCEUSAGE_CONTAINER, RESOURCEUSAGE_ATTACHED }), 
    RESOURCEUSAGE_RESERVED      = #80000000, 
$ 
 
public constant 
    RESOURCEDISPLAYTYPE_GENERIC     =  0, 
    RESOURCEDISPLAYTYPE_DOMAIN      =  1, 
    RESOURCEDISPLAYTYPE_SERVER      =  2, 
    RESOURCEDISPLAYTYPE_SHARE       =  3, 
    RESOURCEDISPLAYTYPE_FILE        =  4, 
    RESOURCEDISPLAYTYPE_GROUP       =  5, 
    RESOURCEDISPLAYTYPE_NETWORK     =  6, 
    RESOURCEDISPLAYTYPE_ROOT        =  7, 
    RESOURCEDISPLAYTYPE_SHAREADMIN  =  8, 
    RESOURCEDISPLAYTYPE_DIRECTORY   =  9, 
    RESOURCEDISPLAYTYPE_TREE        = 10, 
$ 
 
public constant -- structure 
    NETRESOURCE__dwScope        =  0, -- DWORD 
    NETRESOURCE__dwType         =  4, -- DWORD 
    NETRESOURCE__dwDisplayType  =  8, -- DWORD 
    NETRESOURCE__dwUsage        = 12, -- DWORD 
    NETRESOURCE__lpLocalName    = 16, -- LPTSTR 
    NETRESOURCE__lpRemoteName   = 20, -- LPTSTR 
    NETRESOURCE__lpComment      = 24, -- LPTSTR 
    NETRESOURCE__lpProvider     = 28, -- LPTSTR 
    SIZEOF_NETRESOURCE          = 32, 
$ 
 
public atom mpr_dll = open_dll( "mpr.dll" ) 
 
public constant 
    xWNetCloseEnum      = define_c_func( mpr_dll, "WNetCloseEnum", {C_HANDLE}, C_DWORD ), 
    xWNetEnumResource   = define_c_func( mpr_dll, "WNetEnumResourceA", {C_HANDLE,C_POINTER,C_POINTER,C_POINTER}, C_DWORD ), 
    xWNetOpenEnum       = define_c_func( mpr_dll, "WNetOpenEnumA", {C_DWORD,C_DWORD,C_DWORD,C_POINTER,C_POINTER}, C_DWORD ), 
$ 
 
public function WNetCloseEnum( atom hEnum ) 
    return c_func( xWNetCloseEnum, {hEnum} ) 
end function 
 
public function WNetEnumResource( atom hEnum, atom lpcCount, atom lpBuffer, atom lpBufferSize ) 
    return c_func( xWNetEnumResource, {hEnum,lpcCount,lpBuffer,lpBufferSize} ) 
end function 
 
public function WNetOpenEnum( atom dwScope, atom dwType, atom dwUsage, atom lpNetResource, atom lphEnum ) 
    return c_func( xWNetOpenEnum, {dwScope,dwType,dwUsage,lpNetResource,lphEnum} ) 
end function 

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu