Using Win32 functions in Visual FoxPro Image Gallery
Network Management
..msdn
NetApiBufferFree
NetApiBufferSize
NetConnectionEnum
NetFileClose
NetFileEnum
NetFileGetInfo
NetGetDCName
NetGroupEnum
NetLocalGroupEnum
NetMessageBufferSend
NetMessageNameAdd
NetMessageNameDel
NetMessageNameEnum
NetScheduleJobAdd
NetScheduleJobDel
NetScheduleJobEnum
NetServerEnum
NetServerGetInfo
NetSessionEnum
NetShareAdd
NetShareDel
NetShareEnum
NetShareSetInfo
NetUserAdd
NetUserChangePassword
NetUserDel
NetUserEnum
NetUserGetGroups
NetUserGetInfo
NetUserGetLocalGroups
NetUserSetInfo
NetWkstaGetInfo
NetWkstaTransportEnum
NetWkstaUserEnum
Code examples:
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Adding and deleting User Accounts
Enumerating global and local group accounts on a server (WinNT/XP/2K)
Enumerating network sessions established on a server
Finding out if the current user is the Guest account
How to enumerate, add and delete shares on the local computer (WinNT/XP)
Obtaining names of local and global groups for current user (WinNT/XP/2K)
Retrieving configuration information for the specified server (Win2000/XP)
Retrieving configuration information for the specified workstation (Win2000/XP)
Retrieving the name of the primary domain controller (PDC) and join status information
Using NetWkstaTransportEnum to obtain MAC Address of remote server
Using the NetMessageBufferSend to send messages on the network
Using NetWkstaTransportEnum to obtain MAC Address of remote server

User rating: 10/10 (1 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
See also:
  • SendARP function
  • How to retrieve adapter information for the local computer (including MAC address)
  • Obtaining addresses for the adapters on the local computer (Win XP/2003/Vista)
  • How to ping a remote site using IP Helper API calls
  • How to ping a remote site using ICMP API calls

  • #DEFINE MAX_PREFERRED_LENGTH -1
    #DEFINE NERR_Success 0
    
        DO decl
    
        LOCAL cServer, cBuffer, hBuffer, nBufsize,;
            nEntriesRead, nEntriesTotal
    
        * for other computers, not the local computer,
        * convert server name to Unicode
        cServer = null
    *    cServer = StrConv("myserver"+Chr(0), 5)
    
        cBuffer = Repli(Chr(0), 16384)
        STORE 0 TO hBuffer, nBufsize, nEntriesRead, nEntriesTotal
    
        nResult = NetWkstaTransportEnum(cServer, 0, @hBuffer,;
            MAX_PREFERRED_LENGTH, @nEntriesRead, @nEntriesTotal, 0)
    
        IF nResult <> NERR_Success
        * 5=ERROR_ACCESS_DENIED -- connect to the server
        * 53=ERROR_BAD_NETPATH
        * 124=ERROR_INVALID_LEVEL
        * 234=ERROR_MORE_DATA
        * 1113=ERROR_NO_UNICODE_TRANSLATION
        * 2123=The API return buffer is too small
            = NetApiBufferFree(hBuffer)
            ? "Error code:", nResult
            RETURN
        ENDIF
    
        ? "Entries read:", nEntriesRead
    
        * obtain size of the buffer
        = NetApiBufferSize(hBuffer, @nBufsize)
    
        cBuffer = Repli(Chr(0), nBufsize)
        CopyMemory(@cBuffer, hBuffer, nBufsize)
    
    *    ? cBuffer
    
    * this is how you can view and analyze the buffer
    * populated by NetWkstaTransportEnum function
    *    CREATE CURSOR cs (cc C(1), aa I)
    *    FOR ii=1 TO Len(cBuffer)
    *        ch = SUBSTR(cBuffer, ii,1)
    *        INSERT INTO cs VALUES (m.ch, Asc(m.ch))
    *    ENDFOR
    
    *|typedef struct _WKSTA_TRANSPORT_INFO_0 {
    *|  DWORD wkti0_quality_of_service; 0:4
    *|  DWORD wkti0_number_of_vcs;      4:4
    *|  LPWSTR wkti0_transport_name;    8:4
    *|  LMSTR wkti0_transport_address; 12:4
    *|  BOOL wkti0_wan_ish;            16:4
    *|} WKSTA_TRANSPORT_INFO_0, ... total 20 bytes
    #DEFINE TRANSPORT_INFO_SIZE 20
    
        LOCAL nIndex, hName, hAddress, cName, cAddress, ch
        CREATE CURSOR cs (devname C(70), srvaddress C(50))
    
        * retrieving device names and server address for existing
        * transport protocols
        FOR nIndex=1 TO nEntriesRead
            hName = buf2dword(SUBSTR(cBuffer,;
                (nIndex-1)*TRANSPORT_INFO_SIZE+9,4))
    
            hAddress = buf2dword(SUBSTR(cBuffer,;
                (nIndex-1)*TRANSPORT_INFO_SIZE+13,4))
    
            hName = hName - hBuffer  && decrease by initial offset
            cName = ""
            DO WHILE .T.
                ch = SUBSTR(cBuffer, hName, 2)
                IF ch = Chr(0)+Chr(0) Or hName > Len(cBuffer)
                    EXIT
                ENDIF
                cName = cName + ch
                hName = hName + 2
            ENDDO
            cName = STRTRAN(cName, Chr(0), "")
    
            hAddress = hAddress - hBuffer  && decrease by initial offset
            cAddress = ""
            DO WHILE .T.
                ch = SUBSTR(cBuffer, hAddress, 2)
                IF ch = Chr(0)+Chr(0) Or hAddress > Len(cBuffer)
                    EXIT
                ENDIF
                cAddress = cAddress + ch
                hAddress = hAddress + 2
            ENDDO
            cAddress = STRTRAN(cAddress, Chr(0), "")
    
            INSERT INTO cs VALUES (cName, cAddress)
        ENDFOR
    
        = NetApiBufferFree(hBuffer)
    
        SELECT cs
        GO TOP
        BROWSE NORMAL NOWAIT
    * end of main
    
    PROCEDURE decl
    
        DECLARE INTEGER NetWkstaTransportEnum IN netapi32;
            STRING servername, LONG lvl, INTEGER @bufptr,;
            LONG prefmaxlen, LONG @entriesread,;
            LONG @totalentries, LONG resumehandle
    
        DECLARE INTEGER NetApiBufferFree IN netapi32 INTEGER Buffer
    
        DECLARE INTEGER NetApiBufferSize IN netapi32;
            INTEGER Buffer, INTEGER @ByteCount
    
        DECLARE RtlMoveMemory IN kernel32 As CopyMemory;
            STRING @dst, INTEGER src, INTEGER bufsize
    
    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)
    
    
    

    User rating: 10/10 (1 votes)
    Rate this code sample:
    • ~
    3423 bytes  
    Created: 2004-05-29 19:30:27  
    Modified: 2006-07-07 10:00:06  
    Visits in 7 days: 166  
    Listed functions:
    NetApiBufferFree
    NetApiBufferSize
    NetWkstaTransportEnum
    Printer friendly API declarations
    My comment:
    For those who want to improve their MAC address skills :) -- read Three ways to get your MAC address of Khalid Shaikh on the http://www.codeguru.com/.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    There are no notes on this subject.


    Copyright 2001-2017 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.6.38), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.198.246.116)
    14 sec.
    29 sec.Function: 'CreateProcess'
    Function group: 'Process and Thread'
    44 sec.Articles
    58 sec.Function: 'WSACleanup'
    Function group: 'Windows Sockets 2 (Winsock)'
    1.25 min.Function: 'GetProcessTimes'
    1.5 min.Banners
    1.73 min.Function: 'GdipGetImageGraphicsContext'
    Function group: 'GDI+ Image'
    1.93 min.Function: '_lclose'
    Function group: 'File Management'
    2.18 min.Function: 'NetApiBufferFree'
    Function group: 'Network Management'
    2.42 min.Function: 'GdipGetPropertyIdList'
    Function group: 'GDI+ Image'
    Google
    Advertise here!