API添加用户

| |
[不指定 2013/12/22 15:57 | by admin ]

‘转载注明出处,红防安全网 http://blog.h...sp;QQ:3925993
‘以下是用api加用户 原代码
'-------------------------------------------------------------------------------------------------------
#include
#include
#include
#pragma comment(lib,"netapi32")
void usage();
int wmain(int argc, wchar_t *argv[])
{
USER_INFO_1 ui;
DWORD dwError = 0;
if(argc!=3)
{
usage();
return 0;
}
ui.usri1_name = argv[1];
ui.usri1_password = argv[2];
ui.usri1_priv = USER_PRIV_USER;
ui.usri1_home_dir = NULL;
ui.usri1_comment = NULL;
ui.usri1_flags = UF_SCRIPT;
ui.usri1_script_path = NULL;
if(NetUserAdd(NULL, 1, (LPBYTE)&ui, &dwError) == NERR_Success)
{
printf("User has been successfully added\n");
}
else
{
fwprintf(stderr, L"Add user %s Error!\n",argv[1]);
return 1;
}
wchar_t szAccountName[100]={0};
const unsigned short *name;
name=(const unsigned short *)argv[1];
wcscpy(szAccountName,name);
LOCALGROUP_MEMBERS_INFO_3 account;
account.lgrmi3_domainandname=szAccountName;
if( NetLocalGroupAddMembers(NULL,L"Administrators",3,(LPBYTE)&account,1) == NERR_Success )
{
printf("Add to Administrators success.\n");
return 0;
}
else
{
printf("Add to Administrators Fail!\n");
return 1;
}
}
void usage()
{
printf("=======================\n");
printf("====AddUserByApi=======\n");
printf("Team:QQ:3925993/www.hkfx.net\n");
printf("用法:程序 username pass \n");
}
程序源码 | 评论(0) | 引用(0) | 阅读(1832)