Я не знаю, для более простого способа. Это работает путем нахождения каждого запущенного PID и сравнения его имени с «lsass.exe».
// pid.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <windows.h>
#include <psapi.h>
int PrintProcessNameAndID( DWORD processID, const char *name )
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR) );
}
}
if(strcmp(szProcessName, name) == 0) // right process
{
CloseHandle(hProcess);
return 1;
}
// Release the handle to the process.
CloseHandle( hProcess );
return 0;
}
int find(const char *name)
{
// Get the list of process identifiers.
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
{
return 1;
}
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process.
for ( i = 0; i < cProcesses; i++ )
{
if( aProcesses[i] != 0 )
{
if(PrintProcessNameAndID( aProcesses[i], name ))
{
//found it
_tprintf("%d %s\n", aProcesses[i], name);
}
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
find("lsass.exe");
return 0;
}