Sign in to follow this  
Followers 0
Dampe

Netview function?

3 posts in this topic

Anyone written a function that lists all computers on a domain / network?

similar to how net view works?

P.s, I'm looking for a function that uses queries to find the results, not a function that reads / dumps a cmd screen.


Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Global Const $CSIDL_COMPUTERSNEARME = 0x003D

Global $oShell = ObjCreate("Shell.Application") 

;#CS 
#include <Array.au3>

$Arr = _FileFindSpecialFolderEx($CSIDL_COMPUTERSNEARME ,1)

If IsArray($Arr) Then
    _ArrayDisplay($Arr)
Else
    ConsoleWrite($Arr)
EndIf

;#CE 

; =============================================================================================
;
; Function Name:    _FileFindSpecialFolderEx($Folder,[ $ListToArray = 0[, $Filter = 0]])
; Description:     
; Parameter(s):     $Folder      - The Special folder constant (i.e. $MY_COMPUTER)
;                           You could also use an existing path (i.e. "C:\Program Files")
;                           Or a ClassID (i.e. ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} )
;                   $ListToArray - (optional) Change the return value:
;                                   0 = Return the ClassID or Path to the special folder
;                                   1 = Return an array containing the files within the folder
;                   $Filter      - (optional) Filter out the array by:
;                              1 = Files
;                              2 = Folders
;                              3 = Links
;                              4 = ClassId's
;                              0 = No Filter (default)
; Requirement(s):   None.
; Return Value(s):  Returns either:
;                       1) A string containing the CLASSID or Path corresponding to the Special folder
;                       2) An Array containing the list of files/folder/links within the special folder with the type
;                           $OutputArray[$i][0] will contain the list of files/folder/links
;                           $OutputArray[$i][1] will contain the type used by $Filter Parameter 
;                   Returns -1 if there are no results
; Author(s):        Rajesh V R for _FileFindSpecialFolderEx _Kurt for _FileFindSpecialFolder
; Modified:         05 May 2009
; Version:          1.1 includes minor line savings...
; Note(s):          See http://www.microsoft.com for more info
;
;=================================================================================================
Func _FileFindSpecialFolderEx($Folder, $ListToArray = 0, $Filter = 0)
    
    $nPath = $oShell.NameSpace($Folder).Self.Path
    
    If StringLeft($nPath, 1) = ":" Or StringLeft($nPath, 1) = ";" Then
        SetError(2)
    Else
        SetError(1)
    EndIf
    
    If $nPath = "" Then $nPath = -1
    
    If $ListToArray = 0 Then Return $nPath
    
    $nNum = $oShell.NameSpace($Folder).Items.Count
    
    Local $List[$nNum][2], $a = 0, $Itemtype
    
    For $i = 0 To $nNum - 1
        
        $CurrentItem = $oShell.NameSpace($Folder).Items.Item($i)
        
        If $CurrentItem.IsFileSystem = True Then
            If $CurrentItem.IsFolder <> True Then $Itemtype = 1
        EndIf
        
        If $CurrentItem.IsFolder = True Then    $Itemtype = 2
        
        If $CurrentItem.IsLink = True Then  $Itemtype = 3
        
        If StringLeft($CurrentItem.Path, 1) = ":" Or StringLeft($CurrentItem.Path, 1) = ";" Then    $Itemtype = 4
        
        Select
            Case $Filter = 0
                $List[$a][0] = $CurrentItem.Path
                $List[$a][1] = $Itemtype
                $a += 1
            Case $Filter = $Itemtype
                $List[$a][0] = $CurrentItem.Path
                $List[$a][1] = $Itemtype
                $a += 1
        EndSelect

    Next
    If $a = 0 Then
        $List = -1
    Else
        ReDim $List[$a][2]
    EndIf
    Return $List
    
EndFunc   ;==>_FileFindSpecialFolderEx

This will work as long as you are in a network and you have computers to visible in Microsoft Windows Network -> [Your Domain] -> [Neighbour Clients] the above is also achieved using winapi call but not suitable for larger networks.

Edited by rajeshontheweb

Share this post


Link to post
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
Sign in to follow this  
Followers 0