Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Writing entries to custom Event Log
Accessing examples contained in this reference from a VFP application
How to retrieve number of objects in the Recycle Bin
Obtaining information about all user accounts on a server (WinNT only)
Retrieving the name and type of all available RAS-capable devices
Round FoxPro form
Disabling drawing in the VFP form
Displaying printer-properties Property Sheet for the specified printer
GetProcessVersion points at target OS
How to find which fonts Windows uses for drawing captions, menus and message boxes
Retrieving country-specific dialing information from the Windows Telephony list of countries
Setting the date and time that a file was created
The DetectAutoProxyUrl function identifies the auto-config script location
Winsock: reading and setting socket options
Converting a hexadecimal string to an integer
How to control Adobe Reader 9.0 (SDI mode) from VFP application
Using named pipes for interprocess communication
Winsock: resolving an address to a host name
Yet another modal dialog: now HTML-based
Drawing standard Windows icons
Finding out if the current user is the Guest account
How to download this reference`s archive through WinInet functions using InternetOpenUrl
How to make the caption of a VFP application flashing in the Windows task bar
Locking the workstation
Retrieving local computer and user names

User rating: 5/10 (2 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
See also:
  • How to Start a Process as Another User (NT/XP/2K)
  • How to obtain network parameters for the local computer (host, domain, DNS)
  •  
    DO declare
     
    DO GetNames
    DO GetNameEx
    DO GetNameObj
    * end of main
     
    PROCEDURE GetNames
        LOCAL nSize, cBuffer
     
        nSize = 250
        cBuffer = Repli(Chr(0), nSize)
        IF GetComputerName (@cBuffer, @nSize) > 0
            cBuffer = STRTRAN(SUBSTR(cBuffer, 1, nSize), Chr(0),"")
            ? "Computer:", cBuffer
        ENDIF
     
        nSize = 250
        cBuffer = Repli(Chr(0), nSize)
        IF GetUserName (@cBuffer, @nSize) > 0
            cBuffer = STRTRAN(ALLTRIM(SUBSTR (cBuffer, 1, nSize)), Chr(0),"")
            ? "User:", cBuffer
            DO GetSid WITH cBuffer
        ENDIF
     
    PROCEDURE GetNameEx
        LOCAL cBuffer, nBufsize, nIndex
        FOR nIndex=0 TO 7
            nBufsize = 250
            cBuffer = Repli(Chr(0), nBufsize)
            IF GetComputerNameEx(nIndex, @cBuffer, @nBufsize) <> 0
                ? nIndex, LEFT(cBuffer, nBufsize)
            ENDIF
        ENDFOR
     
    PROCEDURE GetNameObj
        LOCAL cBuffer, nBufsize, nIndex
        nBufsize = 250
        cBuffer = Repli(Chr(0), nBufsize)
     
        IF GetComputerObjectName(12, @cBuffer, @nBufsize) = 0
        * 1351 = ERROR_CANT_ACCESS_DOMAIN_INFO
            ? "Error code:", GetLastError()
        ELSE
            ? nBufsize, "Object name: [" +;
                ALLTRIM(LEFT(cBuffer, nBufsize)) + "]"
        ENDIF
     
    PROCEDURE GetSID(cAccount)
        LOCAL hSid, nSidsize, cDomain, nDomainsize, peUse
     
        nSidsize=128
        hSid=LocalAlloc(0, nSidsize)
     
        nDomainsize=250
        cDomain=REPLICATE(CHR(0), nDomainsize)
     
        peUse=0
     
        * retrieve security identifier (SID) for the account name
        = LookupAccountName(NULL, m.cAccount,;
            hSid, @nSidSize, @cDomain, @nDomainSize, @peUse)
     
        * convert the SID to string format
        LOCAL nBuffer, nBufsize, cSid
        nBuffer=0
        = ConvertSidToStringSid(hSid, @nBuffer)
     
        nBufsize = LocalSize(nBuffer)
        cSid = REPLICATE(CHR(0), nBufsize)
        = MemToStr(@cSid, nBuffer, nBufsize)
     
        = LocalFree(nBuffer)
        = LocalFree(hSid)
     
        ? "Domain:", SUBSTR(cDomain, 1, AT(CHR(0),cDomain)-1)
        ? "SID:", cSid
     
    PROCEDURE declare
        DECLARE INTEGER GetLastError IN kernel32
        DECLARE INTEGER LocalFree IN kernel32 INTEGER hMem
        DECLARE LONG LocalSize IN kernel32 INTEGER hMem
     
        DECLARE INTEGER LocalAlloc IN kernel32;
            INTEGER uFlags, INTEGER uBytes
     
        DECLARE INTEGER GetComputerName IN kernel32;
            STRING @lpBuffer, INTEGER @nSize
     
        DECLARE INTEGER GetComputerNameEx IN kernel32;
            INTEGER NameType, STRING @lpBuffer, INTEGER @lpnSize
     
        DECLARE INTEGER GetUserName IN advapi32;
            STRING @lpBuffer, INTEGER @nSize
     
        DECLARE INTEGER GetComputerObjectName IN secur32;
            INTEGER NameFormat, STRING @lpNameBuffer, INTEGER @nSize
     
        DECLARE INTEGER LookupAccountName IN advapi32;
            STRING lpSystemName, STRING lpAccountName,;
            INTEGER Sid, INTEGER @cbSid,;
            STRING @RefDomainName, INTEGER @cchRefDomainName,;
            INTEGER @peUse
     
        DECLARE INTEGER ConvertSidToStringSid IN advapi32;
            INTEGER Sid, INTEGER @StringSid
     
        DECLARE RtlMoveMemory IN kernel32 As MemToStr;
            STRING @dst, INTEGER src, INTEGER nLength
     
     
     

    User rating: 5/10 (2 votes)
    Rate this code sample:
    • ~
    2838 bytes  
    Created: 2001-07-14 12:00:00  
    Modified: 2010-07-31 08:42:48  
    Visits in 7 days: 124  
    Listed functions:
    ConvertSidToStringSid
    GetComputerName
    GetComputerNameEx
    GetComputerObjectName
    GetLastError
    GetUserName
    LocalAlloc
    LocalFree
    LocalSize
    LookupAccountName
    Printer friendly API declarations
    My comment:
    SYS(0) returns current computer and user names.

    Same information can be retrieved with either GETENV() function with "COMPUTERNAME" and "USERNAME" parameters, or with the GetEnvironmentStrings function -- a sample code.
    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.17.109.248)
    4 sec.Function: 'SQLGetInfo'
    11.63 hrs.Function: 'CreateCompatibleBitmap'
     Function: 'AppendMenu'
    13.15 hrs.Function: 'UrlHash'
     Example: 'Simple MAPI: how to resolve a name to unique address list entry'
    14.63 hrs.Function: 'RealGetWindowClass'
    Function group: 'Window'
    15.44 hrs.Function: 'PostMessage'
    Function group: 'Message and Message Queue'
     Function: 'EnumJobs'
    22.87 hrs.Example: 'Retrieving information about the specified icon'
    23.11 hrs.Example: 'Creating a file, then moving it to another destination'
    Google
    Advertise here!