diff --git a/base/shell/explorer/taskswnd.cpp b/base/shell/explorer/taskswnd.cpp index 3d8fd949f7a..100c2eaea07 100644 --- a/base/shell/explorer/taskswnd.cpp +++ b/base/shell/explorer/taskswnd.cpp @@ -340,6 +340,10 @@ GetVersionInfoString(IN LPCWSTR szFileName, OUT LPWSTR szBuffer, IN UINT cbBufLen); +BOOL GetProcessPath(IN DWORD dwProcessId, + OUT LPWSTR szBuffer, + IN DWORD cbBufLen); + class CTaskSwitchWnd : public CComCoClass, public CComObjectRootEx, @@ -681,18 +685,14 @@ public: WCHAR windowText[255]; /* Open process to retrieve the filename of the executable */ - HANDLE hTaskProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, TaskGroup->dwProcessId); - if(hTaskProc != NULL) { - WCHAR ExePath[MAX_PATH] = {}; - - if(GetModuleFileNameExW(hTaskProc, NULL, ExePath, _countof(ExePath)) && GetVersionInfoString(ExePath, L"FileDescription", windowText, _countof(windowText))) { + WCHAR ExePath[MAX_PATH] = {}; + if(GetProcessPath(TaskGroup->dwProcessId, ExePath, _countof(ExePath))) + { + if(GetVersionInfoString(ExePath, L"FileDescription", windowText, _countof(windowText))) tbbi.pszText = windowText; - } if (ExtractIconExW(ExePath, 0, NULL, &icon, 1) <= 0) icon = static_cast(LoadImageW(NULL, MAKEINTRESOURCEW(OIC_SAMPLE), IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE)); - - CloseHandle(hTaskProc); } tbbi.cbSize = sizeof(tbbi); @@ -1007,18 +1007,15 @@ public: } /* Open process to retrieve the filename of the executable */ - HANDLE hTaskProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, TaskGroup->dwProcessId); - if(hTaskProc != NULL) { - WCHAR ExePath[MAX_PATH] = {}; - - if(GetModuleFileNameExW(hTaskProc, NULL, ExePath, _countof(ExePath)) && GetVersionInfoString(ExePath, L"FileDescription", windowText, _countof(windowText))) { + WCHAR ExePath[MAX_PATH] = {}; + if(GetProcessPath(TaskGroup->dwProcessId, ExePath, _countof(ExePath))) + { + if(GetVersionInfoString(ExePath, L"FileDescription", windowText, _countof(windowText))) { tbBtn.iString = (DWORD_PTR) windowText; } if (ExtractIconExW(ExePath, -1, NULL, &icon, 1) <= 0) icon = static_cast(LoadImageW(NULL, MAKEINTRESOURCEW(OIC_SAMPLE), IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE)); - - CloseHandle(hTaskProc); } TaskGroup->IconIndex = ImageList_ReplaceIcon(m_ImageList, -1, icon); @@ -1239,13 +1236,7 @@ public: } WCHAR ItemExePath[MAX_PATH] = {0}; - - HANDLE hTaskProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessId); - if (hTaskProc != NULL) - { - GetModuleFileNameExW(hTaskProc, NULL, ItemExePath, _countof(ItemExePath)); - CloseHandle(hTaskProc); - } + GetProcessPath(dwProcessId, ItemExePath, _countof(ItemExePath)); /* Try to find an existing task group */ TaskGroup = m_TaskGroups; @@ -1260,12 +1251,7 @@ public: else { WCHAR ExePath[MAX_PATH] = {0}; - hTaskProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, TaskGroup->dwProcessId); - if (hTaskProc != NULL) - { - GetModuleFileNameExW(hTaskProc, NULL, ExePath, _countof(ExePath)); - CloseHandle(hTaskProc); - } + GetProcessPath(dwProcessId, ExePath, _countof(ExePath)); if(!lstrcmpW(ExePath, ItemExePath)) { diff --git a/base/shell/explorer/util.cpp b/base/shell/explorer/util.cpp index 76e61164e68..044012e5f15 100644 --- a/base/shell/explorer/util.cpp +++ b/base/shell/explorer/util.cpp @@ -1,5 +1,6 @@ #include "precomp.h" #include +#include typedef struct _LANGCODEPAGE { @@ -257,3 +258,20 @@ GetVersionInfoString(IN LPCWSTR szFileName, return bRet; } + +BOOL GetProcessPath(IN DWORD dwProcessId, + OUT LPWSTR szBuffer, + IN DWORD cbBufLen) +{ + HANDLE hTaskProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessId); + BOOL bRet = FALSE; + if(hTaskProc != NULL) { + if(GetModuleFileNameExW(hTaskProc, NULL, szBuffer, cbBufLen)) { + bRet = TRUE; + } + + CloseHandle(hTaskProc); + } + + return bRet; +}