VirtualBox

Changeset 8897

Show
Ignore:
Timestamp:
05/16/08 16:06:46 (2 months ago)
Author:
vboxsync
Message:

Windows Guest VBoxTray: Implemented single instance checking (global mutex).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp

    r8887 r8897  
    535535int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
    536536{ 
    537     dprintf(("VBoxService: WinMain\n")); 
     537    /* Do not use a global namespace ("Global\\") for mutex name here, will blow up NT4 compatibility! */ 
     538    HANDLE hMutexAppRunning = CreateMutex (NULL, FALSE, "VBoxTray"); 
     539    if (   (hMutexAppRunning != NULL)  
     540        && (GetLastError() == ERROR_ALREADY_EXISTS)) 
     541   { 
     542      /* Close the mutex for this application instance. */ 
     543      CloseHandle (hMutexAppRunning); 
     544      hMutexAppRunning = NULL; 
     545      return 0; 
     546   } 
     547 
     548    dprintf(("VBoxService: Started.\n")); 
     549 
    538550    gInstance = hInstance; 
    539551    VBoxServiceStart(); 
    540      
     552 
     553    dprintf(("VBoxService: Ended.\n")); 
     554 
     555    /* Release instance mutex. */ 
     556    if (hMutexAppRunning != NULL) { 
     557        CloseHandle (hMutexAppRunning); 
     558        hMutexAppRunning = NULL; 
     559    } 
     560 
    541561    return 0; 
    542562} 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy