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 connections made to a shared resource for the local computer (WinNT only)
Enumerating files opened on the network
Enumerating global and local group accounts on a server (WinNT/XP/2K)
Enumerating network sessions established on a server
Enumerating servers of the specified type (e.g. SQL Server) in the primary domain
Finding out if the current user is the Guest account
How to enumerate, add and delete shares on the local computer (WinNT/XP)
Obtaining information about all user accounts on a server (WinNT only)
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 information about all users currently logged on to the workstation (WinNT only)
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
Adding and deleting User Accounts

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:
The class below wraps NetUserAdd, NetUserDel, NetUserGetInfo and NetUserSetInfo API calls with methods that can add, delete and modify user accounts on a server.

Use another example, Obtaining information about all user accounts on a server, to review the user accounts.
 
  Members area. Log in to view this example.
 
  User name:
  Password:
 
 
  Forgot your password?
 
  Sign up for
the Membership
 
 


User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
7151 bytes  
Created: 2005-02-07 19:34:02  
Modified: 2011-12-10 09:20:22  
Visits in 7 days: 178  
Listed functions:
GlobalAlloc
GlobalFree
GlobalSize
NetApiBufferFree
NetApiBufferSize
NetUserAdd
NetUserDel
NetUserGetInfo
NetUserSetInfo
Printer friendly API declarations
My comment:
In VFP versions 3 to 6 you may have to declare RtlMoveMemory as MemToStr and StrToMem not once but every time you call this function with either interface. Newer VFP versions allow at least two API declarations exist simultaneously.

Use this program code to test the class. Replace "MyServer" with an empty string to access user accounts on the local computer.
#DEFINE ERROR_ACCESS_DENIED 5
#DEFINE ERROR_BAD_NETPATH 53
#DEFINE NERR_UserNotFound 2221
#DEFINE NERR_UserExists 2224

LOCAL oUser As UserAccount
oUser = CREATEOBJECT("UserAccount", "MyServer", "FoxApp")

DO CASE

CASE oUser.errorcode = 0
        = MESSAGEBOX("User account " + oUser.GetUsername() +;
                " exists on " + oUser.GetServername() + ". ",;
                64, VERSION())

CASE oUser.errorcode = ERROR_BAD_NETPATH
        = MESSAGEBOX("Server " + oUser.GetServername() +;
                " not found or can not be accessed. ",;
                48, VERSION())

CASE oUser.errorcode = ERROR_ACCESS_DENIED
        = MESSAGEBOX("Access denied to Network " +;
                "Management Functions on " +;
                oUser.GetServername() +;
                ". ", 48, VERSION())

CASE oUser.errorcode = NERR_UserNotFound
        nSelect = MESSAGEBOX("User account " +;
                oUser.GetUsername() +;
                " not found on " + oUser.GetServername() + ". " +;
                CHR(13)+CHR(13) +;
                "Do you want to add this account? ",;
                32+4+256, VERSION())

        IF nSelect = 6
                IF oUser.UserAdd()
                        = MESSAGEBOX("User account " +;
                                oUser.GetUsername() +;
                                " added on " +;
                                oUser.GetServername() + ". ",;
                                64, VERSION())
                ELSE
                        = MESSAGEBOX("Method UserAdd " +;
                                "failed with error code " +;
                                TRANSFORM(oUser.errorcode) + ". ",;
                                48, VERSION())
                ENDIF
        ENDIF
ENDCASE

IF oUser.UserExists()
        oUser.SetComment("Temporary account. Delete after the testing.")
*        oUser.UserDel
ENDIF

* * *
Read an article HOW TO: Add a User to the Local System by Using Directory Services and Visual C# .NET on Microsoft Help and Support web site.
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.147.40.153)
16 sec.Function: 'waveInReset'
Function group: 'Windows Multimedia'
30 sec.Example: 'Retrieving configuration information for the specified workstation (Win2000/XP)'
46 sec.Function: 'CeFindFirstDatabaseEx'
Function group: 'Remote Application Programming (RAPI)'
1.03 min.Example: 'Obtaining names of local and global groups for current user (WinNT/XP/2K)'
1.27 min.
Function group: 'Windows Sockets 2 (Winsock)'
1.55 min.All Functions
1.82 min.Function: 'GetEnvironmentVariable'
Function group: 'Process and Thread'
2.12 min.
Function group: 'Pipe'
2.4 min.Function: 'AVIFileOpen'
Function group: 'Windows Multimedia'
2.93 min.Project
Google
Advertise here!