W2K User Management - Active Directory Instance

zhaozj2021-02-16  101

In actual applications, as we have to do a server to control software on the terminal, you often need to manage users. Of course, NT, W2K provides comprehensive user management mode, but sometimes we don't want to find users management from management tools. This is very troublesome, and we often hope that you can manage NT, W2K users from our software, which is necessary for users who are not very skilled in the operating system. I recently asked me to write a terminal management software, I just thought that there was nothing necessary, but I used to think it was necessary, he used PB, he said that it feels hard to do it. So I have to write a DLL for him, with the addition of the user, delete the user, change the password, increase the user to the group, delete the user, get a list of users, etc., because the space is too long, not convenient for readers to read, I save some functions. If you need, please contact me. gxtlib@21cn.com

The following function mainly uses NT, W2K's Active Directory Services Some component interfaces such as IadsContainer containers, IADS, IADSUSER interfaces, and more.

1. Delete a user (from this machine)

BOOL __stdcall DeleteUser (char * username) {HRESULT hr; IADsContainer * pContainer = NULL; _bstr_t bstr; DWORD ll_len = 255; char lbBuffer [255]; :: GetComputerName (lbBuffer, & ll_len); bstr = "WinNT: //" _BSTR_T (LBBUFFER) "," _ BSTR_T ("Computer"); // Initialization Apartment thread HR = Coinitialize (null); hr = adsgetObject (BSTR, IID_IADSCONTAINER, (void **) & pcontainer; PContainer-> Delete (L "User", _ bstr_t (username)); pcontainer-> release ();

Couninitialize (); return false;}

2, add a user

BOOL __stdcall AddUser (char * username, char * fullname, char * description) {HRESULT hr; IADsContainer * pContainer = NULL; IADs * pADs = NULL; IDispatch * pDisp = NULL; _bstr_t bstr; DWORD ll_len = 255; char lbBuffer [255 ]; :: getcomputername (lbuffer, & ll_len);

BSTR = "Winnt: //" "," _BSTR_T ("Computer"); // Initialization Apartment thread HR = Coinitialize (null); hr = adsgetObject (bstr, IID_IADSCONTAINER, (void **) & pcontainer); HR = PContainer-> Create (l "user", _ bstr_t (username), & pdisp); pcontainer-> release (); if (! successded (hr)) {Return HR;} hr = pdisp-> queryinterface IID_IADS, (void **) & pads; pdisp-> release (); if (! Successded (hr)) {return 0;} variant var; variantinit; var.vt = vt_bstr; var.bstrval = _bstr_t ( FullName); Pads-> Put (L "fullname", var); variantclear (& var); var.vt = vt_bstr; var.bstrval = _bstr_t (description); Pads-> Put (L "description", var); VariantClear (& var);

HR = pads-> setInfo (); hr = pads-> release ();

Couninitialize (); return false;}

3, set user password

Bool __stdcall setuserpwd (char * username, char * pwd) {HRESULT HR; IADSUSER * PUSER; _BSTR_T BSTR; DWORD LL_LEN = 255; Char lbuffer [255]; :: getcomputername (lbbuffer, & ll_len);

BSTR = "Winnt: //" "/" _BSTR_T (UserName) ", User"; File: // Initialization Apartment thread HR = Coinitialize (null); hr = adsgetObject (BSTR, IID_IADSUSER, (void **); if (successded (HR)) {hr = puser-> setpassword (_BSTR_T (PWD)); if (successted (HR)) {couninitialize (); Return True;}} Couninitialize ();

Return false;}

转载请注明原文地址:https://www.9cbs.com/read-10999.html

New Post(0)