Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
OS version and revision
How to create non-blocking Winsock server
How to make the caption of a VFP application flashing in the Windows task bar
Time in milliseconds represented as string (e.g. 1 hour 24 min 36 sec)
Displaying dimmed window behind VFP top-level form
Extensible Storage Engine class library
GetProcessVersion points at target OS
How to block the ALT+TAB shortcut (WinXP)
How to display Windows On-Screen Keyboard
Retrieving the name and type of all available RAS-capable devices
Retrieving the name of the primary domain controller (PDC) and join status information (NT/2000/XP)
Using an Event Object. Part B: running an application responding to events
Using FtpCommand
Retrieving list of available disk drives
Creating a clipping region from the path selected into the device context of a form
Enumerating servers of the specified type (e.g. SQL Server) in the primary domain
How to create a desktop shortcut (shell link)
Placing an arbitrary rectangular area of main VFP window on the Clipboard
Retrieveing general information about the driver and data source associated with an ODBC connection
Retrieving the User Datagram Protocol (UDP) listener table
Winsock: retrieving the standard host name and IP address for the local machine
Adding a background image to VFP report (VFP9, ReportListener)
Monitoring changes occurring within a directory
Using Change Notification Objects to monitor changes to the printer or print server
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: 79  
    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 (54.234.42.16)
    4 sec.Function: 'GetShortPathName'
    13.08 hrs.Function: 'LocalAlloc'
    Function group: 'Memory Management'
     Function: 'CeFindAllFiles'
    Function group: 'Remote Application Programming (RAPI)'
    17.45 hrs.Example: 'Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window'
    19.44 hrs.Example: 'Converting command-line string to a set of Unicode argument strings (WinNT only)'
     Example: 'How to create transparent areas inside a form -- punching holes in the form'
    19.9 hrs.Function: 'CeRapiUninit'
     Function: 'NetServerGetInfo'
    Function group: 'Network Management'
     Example: 'Using IsChild() for testing ThisForm.ShowWindow property'
    23.6 hrs.Example: 'URL: splitting into its component parts'
    Google
    Advertise here!