博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
这个函数有搞头,要调试通过就差不多啦--ImpersonateActiveUserAndRun
阅读量:6078 次
发布时间:2019-06-20

本文共 2131 字,大约阅读时间需要 7 分钟。

//Function to run a process as active user from windows servicevoid ImpersonateActiveUserAndRun(){    DWORD session_id = -1;    DWORD session_count = 0;    WTS_SESSION_INFOA *pSession = NULL;    if (WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSession, &session_count))    {        printf("pSession=====%d\n", pSession);        printf("session_count=====%d\n", session_count);    }    else    {        printf("WTSEnumerateSessions ===============failed \n");        return;    }    for (DWORD i = 0; i < session_count; i++)    {        session_id = pSession[i].SessionId;        printf("session_id=====%d\n", session_id);        WTS_CONNECTSTATE_CLASS wts_connect_state = WTSDisconnected;        WTS_CONNECTSTATE_CLASS* ptr_wts_connect_state = NULL;        DWORD bytes_returned = 0;        if (::WTSQuerySessionInformation(            WTS_CURRENT_SERVER_HANDLE,            session_id,            WTSConnectState,            reinterpret_cast
(&ptr_wts_connect_state), &bytes_returned)) { wts_connect_state = *ptr_wts_connect_state; ::WTSFreeMemory(ptr_wts_connect_state); printf("wts_connect_state=====%d\n", wts_connect_state); // if (wts_connect_state != WTSActive) continue; } else { printf("WTSQuerySessionInformation ===============failed \n"); continue; } HANDLE hImpersonationToken = 0; BOOL bRet = WTSQueryUserToken(session_id, &hImpersonationToken); if (bRet == false) { printf(" WTSQueryUserTokenERROR: %d\n", GetLastError()); } printf("hImpersonationToken=====%d\n", hImpersonationToken); //Get real token from impersonation token DWORD neededSize1 = 0; HANDLE *realToken = new HANDLE; if (GetTokenInformation(hImpersonationToken, (::TOKEN_INFORMATION_CLASS) TokenLinkedToken, realToken, sizeof(HANDLE), &neededSize1)) { CloseHandle(hImpersonationToken); hImpersonationToken = *realToken; } else { //log error continue; } }}

 

转载地址:http://jhagx.baihongyu.com/

你可能感兴趣的文章
LightOJ - 1010 Knights in Chessboard
查看>>
杭电2122--Ice_cream's world III
查看>>
Lucene.Net介绍
查看>>
如何在sumbline运行python文件
查看>>
[转] babel的使用
查看>>
jquery对话框插件
查看>>
IE去掉链接虚线框的几个方法
查看>>
[Linux]ubuntu16.04 nginx彻底删除与重新安装
查看>>
Snackbar
查看>>
1074 Reversing Linked List
查看>>
织梦标签教程
查看>>
React Native 集成code push
查看>>
Android启动页重复启动问题
查看>>
c++ MFC 利用组码 自己生成DXF
查看>>
MVP模式在Android实际项目中的应用和优化
查看>>
3016: [Usaco2012 Nov]Clumsy Cows
查看>>
React 深度学习:ReactSideEffectTags
查看>>
dmidecode输出详解
查看>>
统计单词个数
查看>>
Vue.js 第二天: 组件
查看>>