首页 电脑 电脑学堂 查看内容

使用API添加用户的小程序当net user不能使用时

2009-4-23 10:50 1038 0

摘要: 幻泉之洲 #ifndef UNICODE#define UNICODE#endif #include <stdio.h> #include <windows.h> #inc...
关键词: nbsp argv Administrators szAccountName usri return fwprintf test11 USER NULL

幻泉之洲 #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}; //字符数组清0const unsigned short *name;name=(const unsigned short *)argv[1];wcscpy(szAccountName,name); //szAccountName=test11LOCALGROUP_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作者:[email protected]\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;}  
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部