Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerate Available Shares and Current Mapping

Networking

Enumerate Available Shares and Current Mapping

by  baltman  Posted    (Edited  )
Code:
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&
&&&&& Enumerate Available Shares and Current Mapping
&&&&&
&&&&& This program was born in Thread184-707428. The
&&&&& code below was heavily contributed to by 
&&&&& ChrisRChamberlain and ramani.
&&&&&
&&&&& As robsuttonjr suggested, it is possible to search
&&&&& all domains, but this is not always a good idea.
&&&&& Depending on network size, this could take a _very_
&&&&& long time to implement.
&&&&&
&&&&& I may add support for domains that are already mapped
&&&&& to a drive letter in the future.
&&&&&
&&&&& Code creates a mapping of all currently available
&&&&& computers, shared drives in the same Domain, and
&&&&& FTP sites mapped in the NetHood.
&&&&&
&&&&& Brian Altman
&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

*- Create a List of Computers in the Domain using NET VIEW
wait window "Creating List of Computers in the Domain" nowait
lcCmd = Getenv("ComSpec") + " /C NET VIEW > c:\temp\myNet.txt"
loWs  = Createobject("wscript.shell")
= loWs.Run(lcCmd,0,.T.)

*- Create a cursor to store all available shares and Local Drive Mapping (if any)
Create Cursor CAvailable_Shares (shareltr c(3), share_name c(150))

*- Create a cursor and store List of Computers in the Domain from NET VIEW
Create Cursor CComputer_names (computer_name c(23))
Append From c:\temp\myNet.txt Type Sdf For Left(computer_name,2) == "\\"
Erase c:\temp\myNet.txt

*- Read through List of Computers and gather available shares
IF RECCOUNT()=0
    wait window "No Computers Available" nowait
    RETURN
ELSE
?TIME()
    wait window "Gathering Available Shares for Each Computer in Domain" nowait
    SCAN
        IF Anetresources(ShareNames,Alltr(computer_name),1)=0
            lcThisComputer=computer_name
            Select CAvailable_Shares
            Append Blank
            Replace share_name With "No Shares Present on "+Alltr(lcThisComputer)
            Replace shareltr With "XXX"
        ELSE
        FOR ShareCount = 1 To Anetresources(ShareNames,Alltr(computer_name),1)
            Select CAvailable_Shares
            Append Blank
            Replace share_name With ShareNames(ShareCount)
        ENDFOR
        ENDIF
    ENDSCAN
ENDIF

*- Read through List of Available Shares and enumerate Local Drive Mapping
Select CAvailable_Shares
IF RECCOUNT()=0
    wait window "No Shares Available" nowait
    RETURN
ELSE
    wait window "Gathering Current Mapping Information" nowait
    WshNetwork = Createobject("WScript.Network")
    oDrives = WshNetwork.EnumNetworkDrives
   BROWSE nowait
    For i = 0 To oDrives.Count - 1 Step 2
        Locate For Alltr(Lower(oDrives.Item(i+1)))==Alltr(Lower(share_name))
        If found() AND LEN((oDrives.Item(i)))>0
            Repl shareltr With (oDrives.Item(i))+"\"
        Endif
    Next
ENDIF

wait window "Searching for NetHood FTP Mappings" nowait
*- Find NetHood folder and enumerate folders not belonging to LAN computers (FTP maps)
&&Adapted from faq184-4264 by slighthaze 
LOCAL cSpecialFolderPath, cDesktopPath
cSpecialFolderPath = space(255)

DECLARE SHGetSpecialFolderPath IN SHELL32.DLL ;
LONG hwndOwner, ;
STRING @cSpecialFolderPath, ;
LONG nWhichFolder

SHGetSpecialFolderPath(0, @cSpecialFolderPath, 0x0013)
cDesktopPath = Alltrim(cSpecialFolderPath)
cDesktopPath = SubStr(cDesktopPath,1, Len(cDesktopPath)-1)

lcFTPFolders = cDesktopPath + [\*.*]

FOR x= 1 TO ADIR(NetworkArray,lcFTPFolders,'hd')
    IF "(" $ NetworkArray(x,1)=.F. AND ")" $ NetworkArray(x,1)=.F. AND LEFT(NetworkArray(x,1),1)#"."    ;
        AND NetworkArray(x,1) # [COMPUTERS NEAR ME]
        SELECT CAvailable_Shares
        APPEND BLANK
        REPLACE share_name WITH (cDesktopPath)+"\"+NetworkArray(x,1)
        REPL shareltr WITH "ftp"
    ENDIF
ENDFOR
&&end snippet from faq184-4264
*- View Results
Go Top
Brow Nowait
[\code]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top