Using Win32 functions in Visual FoxPro Image Gallery
Network Management
..msdn
NetApiBufferFree
NetApiBufferSize
NetConnectionEnum
NetFileClose
NetFileEnum
NetFileGetInfo
NetGetDCName
NetGroupEnum
NetLocalGroupEnum
NetMessageBufferSend
NetMessageNameAdd
NetMessageNameDel
NetMessageNameEnum
NetScheduleJobAdd
NetScheduleJobDel
NetScheduleJobEnum
NetServerEnum
NetServerGetInfo
NetSessionEnum
NetShareAdd
NetShareDel
NetShareEnum
NetShareSetInfo
NetUserAdd
NetUserChangePassword
NetUserDel
NetUserEnum
NetUserGetGroups
NetUserGetInfo
NetUserGetLocalGroups
NetUserSetInfo
NetWkstaGetInfo
NetWkstaTransportEnum
NetWkstaUserEnum
Code examples:
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Adding and deleting User Accounts
Enumerating global and local group accounts on a server (WinNT/XP/2K)
Enumerating network sessions established on a server
Finding out if the current user is the Guest account
How to enumerate, add and delete shares on the local computer (WinNT/XP)
Obtaining names of local and global groups for current user (WinNT/XP/2K)
Retrieving configuration information for the specified server (Win2000/XP)
Retrieving configuration information for the specified workstation (Win2000/XP)
Retrieving the name of the primary domain controller (PDC) and join status information
Using NetWkstaTransportEnum to obtain MAC Address of remote server
Using the NetMessageBufferSend to send messages on the network
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: 128  
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.224.18.114)
12 sec.Function: 'RegisterServiceProcess'
Function group: 'Process and Thread'
24 sec.Function: 'waveInGetDevCaps'
Function group: 'Windows Multimedia'
36 sec.Function: 'SQLFreeHandle'
Function group: 'ODBC API'
48 sec.Updates
1.02 min.Gallery
1.23 min.Example: 'Retrieving the interface–to–IP address mapping table'
1.45 min.Function: 'LoadImage'
1.67 min.Function: 'GetMonitorContrast'
Function group: 'Monitor Configuration (Vista)'
2.13 min.
2.4 min.Function: 'CeSeekDatabase'
Function group: 'Remote Application Programming (RAPI)'
Google
Advertise here!