Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get Remote Computer Names in Win95/98?
Message
From
18/09/2002 17:24:54
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Get Remote Computer Names in Win95/98?
Miscellaneous
Thread ID:
00702038
Message ID:
00702038
Views:
70
The code below (originally Ed's I believe) works in Windows NT, 2K, and XP, but not 95/98. How can this be done in Win 95/98? I need to retrieve a list of all computers on the network like the example below does for me and store them in the array Ausers:
PUBLIC ARRAY aUsers(1)
AUsers(1)=""
PRIVATE i, lcNewRemote
i=0
lcNewRemote=""
DO decl 

#DEFINE RESOURCE_CONNECTED  1 
#DEFINE RESOURCE_GLOBALNET  2 
#DEFINE RESOURCE_REMEMBERED 3 
#DEFINE RESOURCE_RECENT     4 
#DEFINE RESOURCE_CONTEXT    5 

#DEFINE RESOURCETYPE_ANY    0 
#DEFINE RESOURCETYPE_DISK   1 
#DEFINE RESOURCETYPE_PRINT  2 

#DEFINE RESOURCEUSAGE_CONNECTABLE 1 
#DEFINE RESOURCEUSAGE_CONTAINER   2 
#DEFINE RESOURCEUSAGE_ATTACHED    16 
#DEFINE RESOURCEUSAGE_ALL         19 

#DEFINE RESOURCEDISPLAYTYPE_DOMAIN   1 
#DEFINE RESOURCEDISPLAYTYPE_SERVER   2 
#DEFINE RESOURCEDISPLAYTYPE_GROUP    5 
#DEFINE RESOURCEDISPLAYTYPE_NETWORK  6 
#DEFINE RESOURCEDISPLAYTYPE_ROOT     7 

#DEFINE NO_ERROR             0 
#DEFINE ERROR_MORE_DATA      234 
#DEFINE ERROR_NO_MORE_ITEMS  259 

#DEFINE NETRESOURCE_SIZE  32 

    LOCAL hEnum, lnResult 
    hEnum = 0 

    lnResult = WNetOpenEnum (RESOURCE_CONTEXT, RESOURCETYPE_ANY,; 
        0, 0, @hEnum) 

    IF lnResult <> NO_ERROR 
    * ERROR_INVALID_PARAMETER = 87 
    * ERROR_NOT_CONTAINER = 1207 
    * ERROR_EXTENDED_ERROR = 1208 
    * ERROR_NO_NETWORK = 1222 
        lcMsg="Unable to start enumeration." 
        lcCode= lnResult
        *? "Unable to start enumeration." 
        *? "Error code:", lnResult 
        RETURN 
    ENDIF 
     
    LOCAL lnCount, lcBuffer, lnBufsize, ii, lcEntry 
    lnCount = -1  && requesting as many entries as possible 
    lnBufsize = 16384  && should be large enough 
    lcBuffer = Repli(Chr(0), lnBufsize) 

    lnResult = WNetEnumResource (hEnum, @lnCount,; 
        @lcBuffer, @lnBufsize) 

    IF lnResult <> NO_ERROR 
        lcMsg= "WNetEnumResource call failed." 
        lcCode= lnResult
        *?"Error code:", lnResult 
        *?"WNetEnumResource call failed." 
    ELSE 
        *? "Number of entries read:", lnCount 
        FOR ii=1 TO lnCount 
            lcEntry = SUBSTR(lcBuffer, (ii-1)*NETRESOURCE_SIZE + 1, NETRESOURCE_SIZE) 
            = SaveEntry(lcEntry) 
        ENDFOR 
    ENDIF 

    = WNetCloseEnum (hEnum) 
IF USED('csResult')
   USE IN csResult
ENDIF
RETURN

PROCEDURE SaveEntry (lcEntry) 
*|typedef struct _NETRESOURCE {  
*|  DWORD  dwScope;        0:4 
*|  DWORD  dwType;         4:4 
*|  DWORD  dwDisplayType;  8:4 
*|  DWORD  dwUsage;       12:4 
*|  LPTSTR lpLocalName;   16:4 
*|  LPTSTR lpRemoteName;  20:4 
*|  LPTSTR lpComment;     24:4 
*|  LPTSTR lpProvider;    28:4 
*|} NETRESOURCE; total bytes = 32 
    LOCAL lnScope, lnType, lnDisplayType, lnUsage,; 
        lcLocalName, lcRemoteName, lcComment, lcProvider 

    lnScope = buf2dword(SUBSTR(lcEntry,  1,4)) 
    lnType = buf2dword(SUBSTR(lcEntry,  5,4)) 
    lnDisplayType = buf2dword(SUBSTR(lcEntry,  9,4)) 
    lnUsage = buf2dword(SUBSTR(lcEntry, 13,4)) 
     
    lcLocalName = mem2str(buf2dword(SUBSTR(lcEntry, 17,4))) 
    lcRemoteName = mem2str(buf2dword(SUBSTR(lcEntry, 21,4))) 
    IF LEN(ALLTRIM(lcRemoteName))>2
       lcNewRemote=RIGHT(lcRemoteName,LEN(ALLTRIM(lcRemoteName))-RAT('\\',lcRemoteName)-1)
       IF ALEN(Ausers,1)=1 .and. Ausers(1)=""
          AUsers(1)=lcNewRemote
       ELSE
          i=ALEN(Ausers,1)+1
          DIMENSION AUsers(i)
          AUsers(i)=lcNewRemote
       ENDIF
*       ?lcNewRemote
    ENDIF
    lcComment = mem2str(buf2dword(SUBSTR(lcEntry, 25,4))) 
    lcProvider = mem2str(buf2dword(SUBSTR(lcEntry, 29,4))) 
     
    IF Not USED("csResult") 
        CREATE CURSOR csResult (dwscope N(16), dwtype N(16), dwdispl N(16),; 
            dwusage N(16), localname C(50), remotename C(50), comment C(50),; 
            provider C(50)) 
    ENDIF 

    INSERT INTO csResult VALUES (lnScope, lnType, lnDisplayType, lnUsage,; 
        lcLocalName, lcRemoteName, lcComment, lcProvider) 
RETURN 

PROCEDURE decl 
    DECLARE INTEGER WNetOpenEnum IN mpr; 
        INTEGER dwScope, INTEGER dwType, INTEGER dwUsage,; 
        INTEGER lpNetResource, INTEGER @lphEnum 

    DECLARE INTEGER WNetCloseEnum IN mpr INTEGER hEnum 

    DECLARE INTEGER WNetEnumResource IN mpr; 
        INTEGER hEnum, INTEGER @lpcCount, STRING @lpBuffer,; 
        INTEGER @lpBufferSize 

FUNCTION  buf2dword (lcBuffer) 
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ; 
    BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +; 
    BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +; 
    BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24) 

FUNCTION  mem2str(lnMemBlock) 
#DEFINE BUFFER_SIZE   16 
#DEFINE EMPTY_BUFFER  Repli(Chr(0), BUFFER_SIZE) 
    IF lnMemBlock = 0 
        RETURN "" 
    ENDIF 

    DECLARE RtlMoveMemory IN kernel32 As Heap2Str; 
        STRING @, INTEGER, INTEGER 

    LOCAL lnPtr, lcResult, lcBuffer, lnPos 
    lnPtr = lnMemBlock 
    lcResult = "" 

    DO WHILE .T. 
        lcBuffer = EMPTY_BUFFER 
        = Heap2Str (@lcBuffer, lnPtr, BUFFER_SIZE) 
        lnPos = AT(Chr(0), lcBuffer) 

        IF lnPos > 0 
            lcResult = lcResult + SUBSTR(lcBuffer, 1, lnPos-1) 
            RETURN  lcResult 
        ELSE 
            lcResult = lcResult + lcBuffer 
            lnPtr = lnPtr + BUFFER_SIZE 
        ENDIF 
    ENDDO 

 
 
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Next
Reply
Map
View

Click here to load this message in the networking platform