Changeset 398


Ignore:
Timestamp:
9/26/2008 4:57:59 AM (6 years ago)
Author:
lowjoel
Message:

Alert the user is the current process is running at a higher privilege level than the previous process. Should fix many elevation issues. Fixes #48

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Eraser.cpp

    r363 r398  
    7676// registered so that we can unregister it in ExitInstance 
    7777static BOOL bClassRegistered = FALSE; 
     78__declspec(dllimport) bool IsProcessElevated(HANDLE process); 
    7879 
    7980BOOL CEraserApp::FirstInstance() 
    8081{ 
    81     CWnd *pWndPrev = CWnd::FindWindow(szEraserClassName, NULL); 
     82    CWnd *pWndPrev = CWnd::FindWindow(szEraserClassName, NULL); 
    8283    CWnd *pWndChild; 
    8384 
     
    8586    if (pWndPrev) 
    8687    { 
     88        // Determine the elevation status of both processes. 
     89        unsigned elevationStatus = 0; 
     90        { 
     91            DWORD pid = 0; 
     92            GetWindowThreadProcessId(pWndPrev->m_hWnd, &pid); 
     93            HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid); 
     94            if (IsProcessElevated(process)) 
     95                elevationStatus |= 2; 
     96            if (IsProcessElevated(GetCurrentProcess())) 
     97                elevationStatus |= 1; 
     98        } 
     99 
     100        if (!(elevationStatus & 2) && (elevationStatus & 1)) 
     101        { 
     102            switch (AfxMessageBox("Another instance of Eraser is still running, but this " 
     103                "new instance is running at a higher privilege level than the other.\n\n" 
     104                "Do you want to close the previous instance? " 
     105                "All active erasing tasks will be terminated", MB_YESNO)) 
     106            { 
     107            case IDYES: 
     108                pWndPrev->SendMessage(WM_CLOSE); 
     109                break; 
     110            } 
     111 
     112            return TRUE; 
     113        } 
     114 
    87115        // if so, does it have any popups? 
    88116        pWndChild = pWndPrev->GetLastActivePopup(); 
Note: See TracChangeset for help on using the changeset viewer.