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. |