Q> Как создать юзера и
дать ему права?
A>
NET_API_STATUS UserAdd(LPSTR username) //(c) Serge Andyk
{
// некоторые используемые функции
описаны выше
USER_INFO_2 user_info;
char compname[256];
wchar_t wcompname[256];
DWORD parm_err=0;
LSA_HANDLE PolicyHandle;
LPTSTR lpszSystemInfo; // ptr. to system info. string
DWORD cchBuff = 256; // size of comp. or user name
TCHAR tchBuffer2[256]; // buffer for concat'd. str.
WCHAR wGroupNameAdd[20]=L"Administrators";
lpszSystemInfo = tchBuffer2;
ZeroMemory(&user_info,sizeof(user_info));
GetComputerName(lpszSystemInfo, &cchBuff);
strcpy(compname,"\\\\");
strcat(compname,lpszSystemInfo);
mbstowcs( wcompname, compname, strlen(compname)+1 );
mbstowcs(user_info.usri2_name,username, strlen(username)+1 );
//-------создаем юзера------------//
user_info.usri2_password = L"";
user_info.usri2_priv = USER_PRIV_USER;
user_info.usri2_flags =
UF_SCRIPT|UF_PASSWD_CANT_CHANGE|UF_DONT_EXPIRE_PASSWD|UF_NORMAL_ACCOUNT;
user_info.usri2_acct_expires=TIMEQ_FOREVER;
NetUserAdd(wcompname,// PDC name
2L, // level
(LPBYTE)&user_info, // input buffer
&parm_err ); // parameter in error
GetAccountSid(
NULL, // default lookup logic
username, // account to obtain SID
&pSid // buffer to allocate to contain resultant SID
);
NetLocalGroupAddMember(0,wGroupNameAdd,pSid);
//---------даем ему кое-какие права-----------//
OpenPolicy(
wcompname, // target machine
POLICY_ALL_ACCESS,
&PolicyHandle // resultant policy handle
);
SetPrivilegeOnAccount(
PolicyHandle, // policy handle
pSid, // SID to grant privilege
L"SeInteractiveLogonRight", // Unicode privilege
TRUE // enable the privilege
);
SetPrivilegeOnAccount(
PolicyHandle,
pSid,
L"SeNetworkLogonRight",
TRUE
);
LsaClose(PolicyHandle);
return 0;
}