Пример #1
0
BOOL GetProcessOwner(DWORD PID, LPTSTR szOwner, DWORD cchSize) {

   // Sanity checks
   if ((PID <= 0) || (szOwner == NULL))
      return(FALSE);

   // Check if we can get information for this process
   HANDLE hProcess = 
      OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, PID);
   if (hProcess == NULL)
      return(FALSE);

   BOOL bReturn = GetProcessOwner(hProcess, szOwner, cchSize);

   // Don't forget to release the process handle
   CloseHandle(hProcess);

   return(bReturn);
}
Пример #2
0
VOID ShowProcessInfo(HWND hwnd, DWORD dwProcessID) {

   SetWindowText(hwnd, TEXT(""));   // Clear the output box

   CToolhelp th(TH32CS_SNAPALL, dwProcessID);

   // Show Process details
   PROCESSENTRY32 pe = { sizeof(pe) };
   BOOL fOk = th.ProcessFirst(&pe);
   for (; fOk; fOk = th.ProcessNext(&pe)) {
      if (pe.th32ProcessID == dwProcessID) {
         TCHAR szCmdLine[1024];
         if (GetProcessCmdLine(dwProcessID, szCmdLine, _countof(szCmdLine))) {
            AddText(hwnd, 
               TEXT("Command line: %s %s\r\n"), pe.szExeFile, szCmdLine);
         } else {
            AddText(hwnd, TEXT("Filename: %s\r\n"), pe.szExeFile);
         }
         AddText(hwnd, TEXT("   PID=%08X, ParentPID=%08X, ")
            TEXT("PriorityClass=%d, Threads=%d, Heaps=%d\r\n"),
            pe.th32ProcessID, pe.th32ParentProcessID, 
            pe.pcPriClassBase, pe.cntThreads,
            th.HowManyHeaps());
         TCHAR szOwner[MAX_PATH+1];
         if (GetProcessOwner(dwProcessID, szOwner, MAX_PATH)) {
            AddText(hwnd, TEXT("Owner: %s\r\n"), szOwner);
         }

         break;   // No need to continue looping
      }
   }


   // Show Modules in the Process
   // Number of characters to display an address
   AddText(hwnd, TEXT("\r\nModules Information:\r\n")
      TEXT("  Usage  %-*s(%-*s)  %10s  Module\r\n"),
      s_cchAddress, TEXT("BaseAddr"),
      s_cchAddress, TEXT("ImagAddr"), TEXT("Size"));

   MODULEENTRY32 me = { sizeof(me) };
   fOk = th.ModuleFirst(&me);
   for (; fOk; fOk = th.ModuleNext(&me)) {
      if (me.ProccntUsage == 65535) {
         // Module was implicitly loaded and cannot be unloaded
         AddText(hwnd, TEXT("  Fixed"));
      } else {
         AddText(hwnd, TEXT("  %5d"), me.ProccntUsage);
      }

      // Try to format the size in kb.
      TCHAR szFormattedSize[64];
      if (StrFormatKBSize(me.modBaseSize, szFormattedSize, 
         _countof(szFormattedSize)) == NULL)
      {
         StringCchPrintf(szFormattedSize, _countof(szFormattedSize), 
            TEXT("%10u"), me.modBaseSize); 
      }
      
      PVOID pvPreferredBaseAddr = 
         GetModulePreferredBaseAddr(pe.th32ProcessID, me.modBaseAddr);
      if (me.modBaseAddr == pvPreferredBaseAddr) {
         AddText(hwnd, TEXT("  %p %*s   %10s  %s\r\n"), 
            me.modBaseAddr, s_cchAddress, TEXT(""), 
            szFormattedSize, me.szExePath);
      } else {
         AddText(hwnd, TEXT("  %p(%p)  %10s  %s\r\n"), 
            me.modBaseAddr, pvPreferredBaseAddr, 
            szFormattedSize, me.szExePath);
      }
   }

   // Show threads in the process
   AddText(hwnd, TEXT("\r\nThread Information:\r\n")
      TEXT("      TID     Priority\r\n"));
   THREADENTRY32 te = { sizeof(te) };
   fOk = th.ThreadFirst(&te);
   for (; fOk; fOk = th.ThreadNext(&te)) {
      if (te.th32OwnerProcessID == dwProcessID) {
         int nPriority = te.tpBasePri + te.tpDeltaPri;
         if ((te.tpBasePri < 16) && (nPriority > 15)) nPriority = 15;
         if ((te.tpBasePri > 15) && (nPriority > 31)) nPriority = 31;
         if ((te.tpBasePri < 16) && (nPriority <  1)) nPriority =  1;
         if ((te.tpBasePri > 15) && (nPriority < 16)) nPriority = 16;
         AddText(hwnd, TEXT("   %08X       %2d\r\n"), 
            te.th32ThreadID, nPriority);
      }
   }
}
/*
 * Sets the title text for the main window.
 */
void Explorerplusplus::HandleMainWindowText(void)
{
	TCHAR	szTitle[512];
	TCHAR	szFolderDisplayName[MAX_PATH];
	TCHAR	szOwner[512];

	/* Don't show full paths for virtual folders (as only the folders
	GUID will be shown). */
	if(m_bShowFullTitlePath && !m_pActiveShellBrowser->InVirtualFolder())
	{
		GetDisplayName(m_CurrentDirectory,szFolderDisplayName,SHGDN_FORPARSING);
	}
	else
	{
		GetDisplayName(m_CurrentDirectory,szFolderDisplayName,SHGDN_NORMAL);
	}

	StringCchPrintf(szTitle,SIZEOF_ARRAY(szTitle),
	_T("%s - Explorer++"),szFolderDisplayName);

	if(m_bShowUserNameInTitleBar || m_bShowPrivilegeLevelInTitleBar)
		StringCchCat(szTitle,SIZEOF_ARRAY(szTitle),_T(" ["));

	if(m_bShowUserNameInTitleBar)
	{
		GetProcessOwner(szOwner,SIZEOF_ARRAY(szOwner));

		StringCchCat(szTitle,SIZEOF_ARRAY(szTitle),szOwner);
	}

	if(m_bShowPrivilegeLevelInTitleBar)
	{
		TCHAR szPrivilegeAddition[64];
		TCHAR szPrivilege[64];

		if(CheckGroupMembership(GROUP_ADMINISTRATORS))
		{
			LoadString(m_hLanguageModule,IDS_PRIVILEGE_LEVEL_ADMINISTRATORS,szPrivilege,SIZEOF_ARRAY(szPrivilege));
		}
		else if(CheckGroupMembership(GROUP_POWERUSERS))
		{
			LoadString(m_hLanguageModule,IDS_PRIVILEGE_LEVEL_POWER_USERS,szPrivilege,SIZEOF_ARRAY(szPrivilege));
		}
		else if(CheckGroupMembership(GROUP_USERS))
		{
			LoadString(m_hLanguageModule,IDS_PRIVILEGE_LEVEL_USERS,szPrivilege,SIZEOF_ARRAY(szPrivilege));
		}
		else if(CheckGroupMembership(GROUP_USERSRESTRICTED))
		{
			LoadString(m_hLanguageModule,IDS_PRIVILEGE_LEVEL_USERS_RESTRICTED,szPrivilege,SIZEOF_ARRAY(szPrivilege));
		}

		if(m_bShowUserNameInTitleBar)
			StringCchPrintf(szPrivilegeAddition,SIZEOF_ARRAY(szPrivilegeAddition),
			_T(" - %s"),szPrivilege);
		else
			StringCchPrintf(szPrivilegeAddition,SIZEOF_ARRAY(szPrivilegeAddition),
			_T("%s"),szPrivilege);

		StringCchCat(szTitle,SIZEOF_ARRAY(szTitle),szPrivilegeAddition);
	}

	if(m_bShowUserNameInTitleBar || m_bShowPrivilegeLevelInTitleBar)
		StringCchCat(szTitle,SIZEOF_ARRAY(szTitle),_T("]"));

	SetWindowText(m_hContainer,szTitle);
}