#ifndef UNICODE #define UNICODE #endif #include <stdio.h> #include <windows.h> #include <lm.h> #pragma comment(lib,"netapi32") int Usage(wchar_t *); int wmain(int argc, wchar_t *argv[]) { USER_INFO_1 ui; DWORD dwError = 0; if(argc!=3) { //fwprintf(stderr,L"usage:%s test11 test123/n",argv[0]); Usage(argv[0]); 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; //添加名为test11的用户,密码为Test!@#123: if(NetUserAdd(NULL, 1, (LPBYTE)&ui, &dwError) == NERR_Success) { //添加成功 fwprintf(stderr, L"User [%s] has been successfully added,password is [%s]/n", argv[1], argv[2]); } else { //添加失败 fwprintf(stderr, L"Add user %s Error!/n",argv[1]); return 1; } wchar_t szAccountName[100]={0}; //字符数组清0 const unsigned short *name; name=(const unsigned short *)argv[1]; wcscpy(szAccountName,name); //szAccountName=test11 LOCALGROUP_MEMBERS_INFO_3 account; account.lgrmi3_domainandname=szAccountName; //把test11添加到Administrators组 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; } } //输出帮助的典型方法: int Usage (wchar_t *username) { fprintf(stdout,"===============================================================================/n" "/t名称:使用API添加用户的小程序/n" "/t作者:pt007@vip.sina.com/n" "/t团队: I.S.T.O信息安全团队(http://blog.csdn.net/I_S_T_O)/n" "/tQQ: 7491805/n" "/t声明:本软件由pt007原创,转载请注明出处,谢谢!/n"); fwprintf(stdout,L"/texample: %s test11 test123/n",username); fprintf(stdout,"===============================================================================/n"); return 1; }