马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

C++取得系统用户权限

[复制链接]
查看3570 | 回复2 | 2015-3-11 15:56:41 | 显示全部楼层 |阅读模式
#include <windows.h>
#include <stdio.h>
#include <lm.h>


#pragma comment (lib, "Mpr.lib")
#pragma comment (lib, "Netapi32.lib")


void getuser(char *);


void main( int argc, char *argv[ ] )
{           //空用户名和密码
DWORD ret;
char username[100] = "", password[100] = "";
char server[100] = "", ipc[100] = "";
NETRESOURCE NET;


if (argc == 1)
{
exit(1);
}


strncpy(server,argv[1],100);
printf("server: %s\n", server);


sprintf(ipc,"\\\\%s\\ipc$",server);


NET.lpLocalName = NULL;
NET.lpProvider = NULL;
NET.dwType = RESOURCETYPE_ANY;
NET.lpRemoteName = (char*)&ipc;


printf("setting up session... ");
ret = WNetAddConnection2(&NET,(const char *)&password,(const char *)&username,0);
                                                                        
//建立空连接
if (ret != ERROR_SUCCESS)
{
printf("IPC$ connect fail.\n");
exit(1);
}
else
printf("IPC$ connect success.\n");
getuser((char*)&server);


printf("Disconnect Server... ");
ret = WNetCancelConnection2((char*)&ipc,0,TRUE);                     //断开IPC连接
if (ret != ERROR_SUCCESS)
{
printf("fail.\n");
exit(1);
}
else
printf("success.\n");
exit (0);
}


void getuser(char *server)                       //取得用户的函数
{
DWORD ret, read, total, resume = 0;
int i;
LPVOID buff;
char comment[255];
wchar_t wserver[100];


do
{
ret = NetLocalGroupEnum(wserver, 1, (unsigned char **)&buff, MAX_PREFERRED_LENGTH, &read, &total, &resume);


if (ret != NERR_Success && ret != ERROR_MORE_DATA)
{
printf("fail\n");
break;
}
PLOCALGROUP_INFO_1 info = (PLOCALGROUP_INFO_1) buff;


for (i=0; i<read; i++)
{
printf("GROUP: %S\n",info[i].lgrpi1_name);


WideCharToMultiByte(CP_ACP, 0, info[i].lgrpi1_comment , -1, comment,255,NULL,NULL);
printf("\tCOMMENT: %s\n",comment);


DWORD ret, read, total, resume = 0;
ret = NetLocalGroupGetMembers((const unsigned short*)&wserver, info[i].lgrpi1_name, 2, (unsigned char **)&buff, 1024, &read, &total, &resume);


if (ret != NERR_Success && ret != ERROR_MORE_DATA)
{
printf("fail\n");
break;
}


PLOCALGROUP_MEMBERS_INFO_2 info = (PLOCALGROUP_MEMBERS_INFO_2) buff;


for (unsigned i=0; i<read; i++)
{
printf("\t\t%S\n", info[i].lgrmi2_domainandname);
printf("\t\t\tSID:%d\n", info[i].lgrmi2_sid);
printf("\t\t\tSIDUSAGE:%d\n",info[i].lgrmi2_sidusage);
}
NetApiBufferFree (buff);
}


NetApiBufferFree (buff);


}
while (ret == ERROR_MORE_DATA );
}
ibcadmin | 2015-3-12 09:20:08 | 显示全部楼层
c++..
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
songyusb | 2015-3-12 09:29:49 | 显示全部楼层
我是路过的酱油哥
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则