kctan
October 25th, 2004, 09:42 PM
My OS is Windows XP Pro, when I run "szExePath", it does not return the full path of the process instead of the process name only. But when I tried to run this program in Windows 98, it shows the full path of the process. Anything I need to do in order to get full path of a process in Windows NT or Windows XP?
sbubis
October 27th, 2004, 02:37 AM
It is not clear from your description which function(s) of API are you using.
I guess that you are doing as follows:
HANDLE hSnapshot;
BOOL b;
hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
b=Process32First (hSnapshot, & procEntry);
while (bRC)
{
printf ("\nProcess <%s>:", pProcEntry->szExeFile);
b = Process32Next (hSnapshot, & procEntry);
}
To get the full path you should work with modules. Like this:
void PrintSnapshot ()
{
HANDLE hSnapshot, hProcSnapshot;
PROCESSENTRY32
procEntry;
MODULEENTRY32
moduleEntry;
BOOL b;
procEntry.dwSize = sizeof (PROCESSENTRY32);
hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
b = Process32First (hSnapshot, & procEntry);
while (b)
{
DWORD dwThreadCnt;
//* print the process info.
PrintProcessInfo (& procEntry);
//* Get information about current process.
hProcSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPALL,
procEntry.th32ProcessID);
//* Modules
moduleEntry.dwSize = sizeof (moduleEntry);
b = Module32First (hProcSnapshot, & moduleEntry);
if (b)
printf ("\n\tList of modules");
else;
while (b)
{
PrintModuleInfo (& moduleEntry);
b = Module32Next (hProcSnapshot, & moduleEntry);
}
CloseHandle (hProcSnapshot);
//* Go to the next process
b = Process32Next (hSnapshot, & procEntry);
}
CloseHandle (hSnapshot);
}
//**************************************************************
void PrintProcessInfo (PROCESSENTRY32 *pProcEntry)
{
printf ("\nProcess <%s>:", strupr (pProcEntry->szExeFile));
printf ("\n\tNumber of references to the process=%d",
pProcEntry->cntUsage);
printf ("\n\tIdentifier of the process=0x%8.8X",
pProcEntry->th32ProcessID);
printf ("\n\tNumber of execution threads started by the process=%d",
pProcEntry->cntThreads);
printf ("\n\tBase priority=%d", pProcEntry->pcPriClassBase );
}
//**************************************************************
void PrintModuleInfo (MODULEENTRY32 *pModuleEntry)
{
printf ("\n\tModule name: %s", pModuleEntry->szModule);
printf ("\n\tLocation of the module: %s", pModuleEntry->szExePath);
}
Since a process can consist of several modules the full path of each module, including executable itself is in the MODULEENTRY32 structure.
Hope it helps.
kctan
October 27th, 2004, 04:02 AM
Some of the services couldn't display the full path also.......
sbubis
October 27th, 2004, 07:17 AM
Unfortunately, I cannot say you exactly why it is so.
Probably, you should use EnumProcessModules mechanism from PSAPI.
For each module handle you can then call GetModuleFileName function to retrieve its full file name.