Using Win32 functions in Visual FoxPro Image Gallery
System Information
..msdn
ExpandEnvironmentStrings
GetComputerName
GetComputerNameEx
GetComputerObjectName
GetCurrentHwProfile
GetKeyboardType
GetNativeSystemInfo
GetProductInfo
GetSysColor
GetSystemDirectory
GetSystemInfo
GetSystemMetrics
GetSystemRegistryQuota
GetSystemWow64Directory
GetUserName
GetUserNameEx
GetVersion
GetVersionEx
GetWindowsDirectory
IsNetworkAlive
SetComputerName
SetSysColors
SystemParametersInfo
Code examples:
Finding out if the current user is the Guest account
Obtaining names of local and global groups for current user (WinNT/XP/2K)
Retrieving local computer and user names
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: 131  
    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-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.196.47.128)
    4 sec.Links
    7 sec.Updates
    10 sec.Function: 'closesocket'
    Function group: 'Windows Sockets 2 (Winsock)'
    13 sec.Login
    16 sec.Function: 'ReadFile'
    Function group: 'File Management'
    19 sec.Function: 'MoveFile'
    Function group: 'File Management'
    27 sec.Function: 'CeReadFile'
    Function group: 'Remote Application Programming (RAPI)'
    31 sec.Function: 'OpenProcess'
    Function group: 'Process and Thread'
    35 sec.Example: 'How to view icons stored in executable files (Icon Viewer) - II'
    39 sec.Example: 'How to prevent users from accessing the Windows Desktop and from switching to other applications'
    Google
    Advertise here!