Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Disconnecting USB Mass Storage Device programmatically
Displaying Windows shell folders in TreeView control with Visual FoxPro FLL
Displaying bitmap using the AlphaBlend function
Displaying system dialog that selects a folder
How to build UDP responder
How to find when the application started
OS version and revision
Obtaining some properties for the Windows desktop using the GetWindowPlacement function
Using the SetErrorMode for determining if a floppy drive is ready
Winsock: retrieving directory listing from an FTP server using passive data connection (FTP, port 21)
Listing child windows for the Windows desktop
Winsock: changing the byte ordering
Adding user-defined items to the Control Menu of VFP form (requires VFP9)
Converting command-line string to a set of Unicode argument strings (WinNT only)
Exporting DLL icon resources as .ICO files
How to find which fonts Windows uses for drawing captions, menus and message boxes
Printing text on the main VFP window
Retrieving top-child window for the VFP form
Deleting files into the Recycle Bin
Enumerating network interfaces on the local computer
How to ping a remote site using IP Helper API calls
Retrieving the IP-to-physical address mapping table
Using InternetSetFilePointer when resuming interrupted download from the Internet
Winsock: how to retrieve a service information corresponding to a service name
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: 94  
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-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 (107.20.7.65)
1.29 hrs.Example: 'Exporting DLL icon resources as .ICO files'
 Function: 'GdipResetWorldTransform'
Function group: 'GDI+ Graphics'
2.24 hrs.Function: 'mixerGetLineControls'
Function group: 'Windows Multimedia'
3.24 hrs.Function: 'SizeofResource'
 Function: 'GlobalFree'
Function group: 'Memory Management'
4.82 hrs.Example: 'Listing INF files in a specified directory'
 Function: 'CreatePopupMenu'
Function group: 'Menu'
5.89 hrs.Function: 'StretchDIBits'
Function group: 'Bitmap'
6.37 hrs.Example: 'How to display the Properties dialog box for a file (ShellExecuteEx)'
 Function: 'LogonUser'
Function group: 'Security'
Google
Advertise here!