Jump to content

Enum share list : ~ Net view /all


Suba
 Share

Recommended Posts

Hello,

I've been searching for a few hours how i could list the shared folders on a server and I only found the _Net_Share_ShareEnum function.

Unfortunatly .. Administrator, Power User, Print Operator, or Server Operator group membership is required to execute this function.

So .. Here is a variation to enumerate the share without specific group membership :

#include <Array.au3>
#include <NetShare.au3>
Global Const $tagSHARE_INFO_1 = "ptr NetName;dword Type;ptr Remark"

Global $aInfo = _Net_Share_ShareEnumSimple("ServerName")
_ArrayDisplay($aInfo)


; #FUNCTION# ====================================================================================================================
; Name...........: _Net_Share_ShareEnum
; Description ...: Retrieves information about each shared resource on a server. Type
; Syntax.........: _Net_Share_ShareEnum([$sServer = ""])
; Parameters ....: $sServer - String that specifies the DNS or NetBIOS name of the remote server on which the function is  to
;                  +execute. If this parameter is blank the local computer is  used.
;                  $sType - Int that specifies the type of informations to retrieve (1 = Enumerate the shared directories, 
;                  2 = Enumerate the shared directories with details informations such as permisions ..)
; Return values .: Success      - Type 1 : [x][3] ~ Type 2 : [x][7] Array with the following format:;                  
;                  |[0][0] - Number of entries in array
;                  |[1][0] - Share name of a resource
;                  |[1][1] - Type of the shared resource. Can be a combination of:
;                  | $STYPE_DISKTREE  - Print queue
;                  | $STYPE_PRINTQ    - Disk drive
;                  | $STYPE_DEVICE    - Communication device
;                  | $STYPE_IPC       - IPC
;                  | $STYPE_SPECIAL   - Special share reserved for IPC$ or remote administration of the server
;                  | $STYPE_TEMPORARY - A temporary share
;                  |[1][2] - Contains an optional comment about the shared resource
;                  |[1][3] - Indicates the shared resource's permissions:
;                  |  1 - Permission to read data from a resource and to execute
;                  |  2 - Permission to write data to the resource
;                  |  4 - Permission to create an instance of the resource
;                  |  8 - Permission to execute the resource
;                  | 16 - Permission to delete the resource
;                  | 32 - Permission to modify the resource's attributes
;                  | 64 - Permission to modify the permissions assigned to a resource
;                  |[1][4] - Maximum number of concurrent connections for the resource
;                  |[1][5] - Indicates the number of current connections to the resource
;                  |[1][6] - Specifies the local path for the shared resource
;                  |[1][7] - Specifies the share's password
; Author ........: Paul Campbell (PaulIA)
; Modified.......: Michiels Jean-Jacques (Suba) (21/06/2011)
; Remarks .......: Administrator, Power User, Print Operator, or Server Operator group membership is  required  to  execute  this
;                  function.
; Related .......: _Net_Share_FileEnum, _Net_Share_SessionEnum
; Link ..........: @@MsdnLink@@ NetShareEnum, _Net_Share_ConnectionEnum
; Example .......: Yes
; ===============================================================================================================================
Func _Net_Share_ShareEnumSimple($sServer = "", $sType = 1)
    If $sServer = "" Then $sServer = "127.0.0.1"
    If StringLeft($sServer, 2) <> "\\"  Then $sServer = "\\" & $sServer 
    Local $aResult = DllCall("netapi32.dll", "int", "NetShareEnum", "wstr", $sServer, "dword", $sType, "ptr*", 0, "dword", -1, _
            "dword*", 0, "dword*", 0, "ptr", 0)
            
    If @error Then Return SetError(@error, @extended, 0)
    If $sType <> 1 And $sType <> 2 Then Return 0
    
    Local $iCount = $aResult[5]
    
    If $sType = 2 Then      
        Local $aInfo[$iCount + 1][8]
        $aInfo[0][0] = $iCount
        If $aResult[0] = 0 Then
            Local $pInfo = $aResult[3]
            Local $tInfo
            For $iI = 1 To $iCount
                $tInfo = DllStructCreate($tagSHARE_INFO_1, $pInfo)
                $aInfo[$iI][0] = _WinAPI_WideCharToMultiByte(DllStructGetData($tInfo, "NetName"))
                $aInfo[$iI][1] = DllStructGetData($tInfo, "Type")
                $aInfo[$iI][2] = _WinAPI_WideCharToMultiByte(DllStructGetData($tInfo, "Remark"))
                $aInfo[$iI][3] = DllStructGetData($tInfo, "Permissions")
                $aInfo[$iI][4] = DllStructGetData($tInfo, "MaxUses")
                $aInfo[$iI][5] = DllStructGetData($tInfo, "CurrentUses")
                $aInfo[$iI][6] = _WinAPI_WideCharToMultiByte(DllStructGetData($tInfo, "Path"))
                $aInfo[$iI][7] = _WinAPI_WideCharToMultiByte(DllStructGetData($tInfo, "Password"))
                $pInfo += DllStructGetSize($tInfo)
            Next
        EndIf   
    Else
        Local $aInfo[$iCount + 1][3]
        $aInfo[0][0] = $iCount
        If $aResult[0] = 0 Then
            Local $pInfo = $aResult[3]
            Local $tInfo
            For $iI = 1 To $iCount
                $tInfo = DllStructCreate($tagSHARE_INFO_1, $pInfo)
                $aInfo[$iI][0] = _WinAPI_WideCharToMultiByte(DllStructGetData($tInfo, "NetName"))
                $aInfo[$iI][1] = DllStructGetData($tInfo, "Type")
                $aInfo[$iI][2] = _WinAPI_WideCharToMultiByte(DllStructGetData($tInfo, "Remark"))
                $pInfo += DllStructGetSize($tInfo)
            Next
        EndIf
    EndIf

    __Net_Share_APIBufferFree($aResult[3])
    Return SetExtended($aResult[0], $aInfo)
EndFunc   ;==>_Net_Share_ShareEnum

(I dunno if there is an other function or method, anyway i did not found it :huh2: )

Edited by Suba
Link to comment
Share on other sites

  • 5 years later...

Sorry to bring up this, I tried this script but it only generates a blank box. 

I would like to understand how net view /all can be replicated. (no administrator, power user membership group required)

Could someone tell me if it is working?

Link to comment
Share on other sites

  • Moderators

@RoloTomassi it works just fine for me. If you are having a problem, I would suggest you create a thread in the General Help and Support forum and post the exact code you're using. You can link back to this thread as an example of where you got the code from. This will put many more eyes on your problem.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...