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
Finding out if the current user is the Guest account

User rating: 0/10 (0 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:
In the code sample below, the CurrentUser class wraps call to the NetUserGetInfo that populates USER_INFO_1 structure for the current user.

The usri1_priv member of this struture indicates if the user account is Guest or Admin.
LOCAL oUser As CurrentUser
oUser = CREATEOBJECT("CurrentUser")
WITH oUser
    ? .GetUserName()
    ? .IsUserAdmin()
    ? .IsUserGuest()
ENDWITH
* end of main

DEFINE CLASS CurrentUser As Session
#DEFINE USER_PRIV_GUEST 0
#DEFINE USER_PRIV_USER 1
#DEFINE USER_PRIV_ADMIN 2

    PROTECTED UserName, UserPrivLevel
    UserName=""
    UserPrivLevel=0

PROCEDURE Init
    THIS.declare
    THIS.GetUserInfo

FUNCTION IsUserAdmin() As Boolean
RETURN (BITAND(THIS.UserPrivLevel,;
    USER_PRIV_ADMIN) <> 0)

FUNCTION IsUserGuest() As Boolean
RETURN (BITAND(THIS.UserPrivLevel,;
    USER_PRIV_GUEST) <> 0)

FUNCTION GetUserName() As String
RETURN THIS.UserName

PROCEDURE GetUserInfo
    LOCAL nUserInfo, nBufSize, cUserInfo
    STORE 0 TO nUserInfo, nBufSize

    WITH THIS
        .UserName=.GetCurrentUserName()

        * USER_INFO_1
        = NetUserGetInfo(NULL, .ToUnicode(.UserName),;
            1, @nUserInfo)

        NetApiBufferSize(nUserInfo, @nBufSize)

        cUserInfo = REPLICATE(CHR(0), nBufSize)
        MemToStr(@cUserInfo, nUserInfo, nBufSize)

        * 13=offset to usri1_priv member; 4=DWORD
        .UserPrivLevel = .buf2dword(;
            SUBSTR(m.cUserInfo, 13, 4))
    ENDWITH

PROTECTED FUNCTION GetCurrentUserName() As String
* just an example; parsing SYS(0) would suffice
    LOCAL nBufSize, cUserName
    nBufSize=0
    = GetUserName(NULL, @nBufSize)
    cUserName = REPLICATE(CHR(0), nBufSize)
    = GetUserName(@cUserName, @nBufSize)
RETURN STRTRAN(cUserName, CHR(0), "")

PROTECTED PROCEDURE declare

    DECLARE INTEGER NetUserGetInfo IN netapi32;
        STRING servername, STRING username,;
        INTEGER lvl, INTEGER @bufptr

    DECLARE INTEGER GetUserName IN advapi32;
        STRING @lpBuffer, INTEGER @nSize

    DECLARE INTEGER NetApiBufferFree IN netapi32;
        INTEGER Buffer

    DECLARE INTEGER NetApiBufferSize IN netapi32;
        INTEGER Buffer, INTEGER @ByteCount

    DECLARE RtlMoveMemory IN kernel32 As MemToStr;
        STRING @dst, INTEGER src, INTEGER nLen

PROTECTED FUNCTION ToUnicode(cStr As String) As String
RETURN STRCONV(m.cStr, 5)

PROTECTED FUNCTION buf2dword(cBuffer)
RETURN Asc(SUBSTR(cBuffer, 1,1)) + ;
    BitLShift(Asc(SUBSTR(cBuffer, 2,1)),  8) +;
    BitLShift(Asc(SUBSTR(cBuffer, 3,1)), 16) +;
    BitLShift(Asc(SUBSTR(cBuffer, 4,1)), 24)

ENDDEFINE

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2235 bytes  
Created: 2010-07-06 09:03:19  
Modified: 2010-07-06 09:39:24  
Visits in 7 days: 114  
Listed functions:
GetUserName
NetApiBufferFree
NetApiBufferSize
NetUserGetInfo
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-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.2.110)
9 sec.Example: 'Windows Shell Icons displayed and exported to ICO files (Vista)'
19 sec.Function: 'waveOutOpen'
Function group: 'Windows Multimedia'
42 sec.Function: 'FileTimeToSystemTime'
54 sec.Function: 'GetMenuItemID'
Function group: 'Menu'
1.1 min.Function: 'SetDefaultPrinter'
Function group: 'Printing and Print Spooler'
1.28 min.Example: 'How to change display settings: screen resolution, screen refresh rate'
1.5 min.All Functions
1.7 min.Function: 'getnameinfo'
Function group: 'Windows Sockets 2 (Winsock)'
1.88 min.
Function group: 'Security'
2.1 min.Function: 'GetVolumeInformation'
Function group: 'File System'
Google
Advertise here!