Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Adding a background image to VFP report (VFP9, ReportListener)
Displaying OS Memory Status
Enumerating printer drivers installed
Form Magnifier
Storing content of the Clipboard to a bitmap file
Adding printer to the list of supported printers for the specified server
Number of clipboard formats available
A client for testing non-blocking Winsock server
Displaying icons in the system tray (VFP9)
How to find the application associated with a file name
Using the IsWindowEnabled function
Enumerating servers of the specified type (e.g. SQL Server) in the primary domain
Exporting DLL icon resources as .ICO files
Extensible Storage Engine class library
GDI+: sending image of FoxPro form to printer
How to enable the SE_SHUTDOWN_NAME privilege for the application
Obtaining names of local and global groups for current user (WinNT/XP/2K)
Obtaining Shell32.dll version
Testing MS Internet Explorer version installed
Time in milliseconds represented as string (e.g. 1 hour 24 min 36 sec)
Using GetBinaryType (WinNT only) to determine the type of an executable file
Using NetWkstaTransportEnum to obtain MAC Address of remote server
Windows Shell Icons displayed and exported to ICO files (Vista)
Finding the path to the VFP executable running
Obtaining names of local and global groups for current user (WinNT/XP/2K)

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:
  • Enumerating global and local group accounts on a server (WinNT/XP/2K)
  • Enumerating sessions established on a server

  •  
    DO decl
     
    cServer = ""  && empty value means local computer
    *cServer = "\\MYSERVER"
    cUser = GetUsrName()  && current user
     
    = ListGroups(cServer, cUser)  && local groups
    = ListGroups(cServer, cUser, .T.)  && global groups
    * end of main
     
    PROCEDURE ListGroups(cServer, cUser, lGlobal)
    #DEFINE MAX_PREFERRED_LENGTH -1
     
        LOCAL hBuffer, nBufsize, nReadCount, nTotalCount, nResult,;
            cBuffer, nIndex, nPtr, nOffs, nLen, cGroup
     
        STORE 0 TO nReadCount, nTotalCount, hBuffer
     
        cServer = StrConv(cServer+Chr(0), 5)
        cUser = StrConv(cUser+Chr(0), 5)
     
        IF lGlobal
            nResult = NetUserGetGroups(cServer, cUser, 0,;
                @hBuffer, MAX_PREFERRED_LENGTH, @nReadCount, @nTotalCount)
        ELSE
            nResult = NetUserGetLocalGroups(cServer, cUser, 0,0,;
                @hBuffer, MAX_PREFERRED_LENGTH, @nReadCount, @nTotalCount)
        ENDIF
     
        IF nResult <> 0 Or hBuffer=0
            = NetApiBufferFree(hBuffer)
            ? "Error code:", nResult
            RETURN
        ENDIF
     
        * size of the buffer allocated by the system
        * GlobalSize on Windows XP returns same result
        nBufsize = 0
        = NetApiBufferSize(hBuffer, @nBufsize)
     
        * copying data from memory buffer to FoxPro string
        cBuffer = Repli(Chr(0), nBufsize)
        CopyMemory(@cBuffer, hBuffer, nBufsize)
     
        * scanning group names
        FOR nIndex=1 TO nTotalCount
            * retrieving 4-byte (DWORD) address of Unicode string
            * that specifies the group name
            nPtr = buf2dword(SUBSTR(cBuffer, (nIndex-1)*4+1,4))
     
            * matching memory addresses to cBuffer string
            nOffs = nPtr - hBuffer + 1
            cGroup = SUBSTR(cBuffer, nOffs)+Chr(0)+Chr(0)
            nLen = AT(Chr(0)+Chr(0), cGroup)
            cGroup = SUBSTR(cGroup, 1, nLen)
     
            ? nIndex, StrConv(cGroup, 6)
        ENDFOR
        = NetApiBufferFree(hBuffer)
     
    FUNCTION GetUsrName
    * actually SYS(0) is Ok too :)
        LOCAL cBuffer, nBufsize
        nBufsize = 32
        cBuffer = Repli(Chr(0), nBufsize)
        = GetUserName(@cBuffer, @nBufsize)
    RETURN STRTRAN(cBuffer, Chr(0), "")
     
    PROCEDURE decl
        DECLARE INTEGER NetUserGetGroups IN netapi32;
            STRING servername, STRING username, INTEGER lvl,;
            INTEGER @bufptr, INTEGER prefmaxlen,;
            INTEGER @entriesread, INTEGER @totalentries
     
        DECLARE INTEGER NetUserGetLocalGroups IN netapi32;
            STRING servername, STRING username, INTEGER lvl,;
            INTEGER flgs, INTEGER @bufptr, INTEGER prefmaxlen,;
            INTEGER @entriesread, INTEGER @totalentries
     
        DECLARE INTEGER GetUserName IN advapi32;
            STRING  @lpBuffer, INTEGER @nSize
     
        DECLARE RtlMoveMemory IN kernel32 As CopyMemory;
            STRING @dst, INTEGER src, INTEGER bufsize
     
        DECLARE INTEGER NetApiBufferFree IN netapi32 INTEGER buffer
     
        DECLARE INTEGER NetApiBufferSize IN netapi32;
            INTEGER Buffer, INTEGER @ByteCount
     
    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:
    • ~
    2866 bytes  
    Created: 2003-12-05 20:41:44  
    Modified: 2011-12-10 09:20:22  
    Visits in 7 days: 120  
    Listed functions:
    GetUserName
    GlobalSize
    NetApiBufferFree
    NetApiBufferSize
    NetUserGetGroups
    NetUserGetLocalGroups
    Printer friendly API declarations
    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-2013 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.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (50.19.155.235)
    9.86 hrs.Example: 'Using the Semaphore object'
    9.87 hrs.Function: 'SetFilePointerEx'
    Function group: 'File Management'
    16.96 hrs.Example: 'Displaying the associated icons and descriptions for files and folders'
     Example: 'Using Beep and Sleep functions to make the old tin buzz sing (WinNT only?)'
    16.97 hrs.Example: 'How to create MD-5 and SHA-1 hash values from a string'
    18.26 hrs.Example: 'Using an Event Object. Part A: running an application that creates an Event object'
     Function: 'AlphaBlend'
    21.64 hrs.Example: 'How to view system icons for the classes installed on the local machine'
     Example: 'How to print FoxPro form -- II'
    22.81 hrs.Example: 'Winsock: how to retrieve a service information corresponding to a port'
    Google
    Advertise here!