Get information about the owner of the current process

xiaoxiao2021-03-06  71

The main design code is as follows:

#include

.......

Clistctrl m_strlist;

CSTRING M_STRVALUE;

.......

/ / Get information about the owner of the current process

Void ONGETUSER ()

{

// Todo: Add Your Control Notification Handler Code Here

Updatedata ();

IF (M_StrValue.Isempty ())

{

AfxMessageBox (_T ("Process ID Is Empty!");

Return;

}

INT NID = atol (m_StrValue);

CString Str;

GetProcessauth (STR, NID);

IF (strPathvalid.isempty ())

{

AFXMessageBox (_T ("Get The Path Failed!");

}

Else

{

AfxMessageBox (STRPATHVALID);

}

}

/ / Read the information of the owner of the current process

Void getProcessauth (CString Strpath, Long PID)

{

// Get the user identity of the running process, there is no problem with 8 or more processes, and the 8,0 process cannot be listed (8 is Win2000, WinXP is 4)

SID_NAME_USE PEUSE;

Handle HP;

Handle htokeen;

Int isok;

Char buf [0x400];

Char BUF1 [100];

Char BUF2 [100];

DWORD DWNUMBYTESRET;

DWORD DWNUMBYTESRET1;

HP = OpenProcess (0x400, 0, pid); // 0x400 IS process_Query_information

Isok = openprocessToken (HP, 0x20008, & HToken); // This 0x20008 doesn't know what, token_query?

IF (ISOK)

{

Isok = GetTokenInformation (HToken, Tokenuser, & Buf, 0x400, & DWNumBytesret);

IF (ISOK)

{

DWNumBytesret = 100;

DwnumBytesret1 = 100;

Isok = lookupaccountsid (NULL, (DWORD *) (* (DWORD *) BUF), BUF1, & DWNUMBYTESRET, BUF2, & DWNUMBYTESRET1, & PEUSE

IF (ISOK)

{

StrPath.Format ("Run Auth:% S //% S", BUF2, BUF1);

StrPathvalid = strpath;

}

CloseHandle (HTOKEN);

}

}

CloseHandle (HP);

}

/ / Get the current list of processes

Void ListProcess ()

{

m_strlist.deleteallItems ();

While (m_strlist.deletecolumn (0));

m_strlist.modifystyle (0, LVS_REPORT);

m_strlist.insertcolumn (0, "Process ID", LVCFMT_LEFT, 80);

m_strlist.insertcolumn (1, "Process Name", LVCFMT_LEFT, 150);

Handle Handle = CreateToolHelp32Snapshot (TH32CS_SNAPPROCESS, 0); ProcesSsentry32 * info = new processry12;

Info-> dwsize = sizeof (Processentry32);

INT i = 0;

IF (Process32First (Handle, INFO)

{

IF (getLastError () == Error_no_more_files)

{

AfxMessageBox ("no more process");

}

Else

{

CString ID;

ID.Format ("% d", info-> t32processid);

m_strlist.insertitem (i, id);

M_Strlist.SetItemData (I, Info-> TH32ProcessID);

ID.Format ("% s", info-> szexefile);

m_strlist.setitemtext (i, 1, ID);

i ;

While (Process32Next (Handle, INFO)! = false)

{

Id.format ("% 5D", Info-> TH32Processid);

m_strlist.insertitem (i, id);

M_Strlist.SetItemData (I, Info-> TH32ProcessID);

ID.Format ("% s", info-> szexefile);

m_strlist.setitemtext (i, 1, id);

i ;

}

}

}

CloseHandle (Handle);

DELETE INFO;

}

// Get the process identity of the process of clicking the list

Void cgetprocessusermfcdlg :: OnClickListCtrl (nmhdr * pnmhdr, lresult * pRESULT)

{

// Todo: Add Your Control Notification Handler Code Here

Position POS = m_strlist.getfirstselectedItemPosition ();

Int select = m_strlist.getnextSelectedItem (POS);

Setdlgitemint (idc_process_id, m_strlist.getitemdata;);

* PRESULT = 0;

}

转载请注明原文地址:https://www.9cbs.com/read-91311.html

New Post(0)