VBoxGuestInst.cpp revision ac1c6dacf552b38d984953b5b31910a4036e0815
/* $Id$ */
/** @file
* Small tool to (un)install the VBoxGuest device driver.
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <VBox/VBoxGuest.h>
//#define TESTMODE
static int installDriver(void)
{
/*
* Assume it didn't exist, so we'll create the service.
*/
if (!hSMgrCreate)
{
return -1;
}
"VBoxGuest Support Driver",
"System",
if (!hService)
else
return hService ? 0 : -1;
}
static int uninstallDriver(void)
{
int rc = -1;
if (!hSMgr)
{
return -1;
}
if (hService)
{
/*
* Delete the service.
*/
if (DeleteService(hService))
rc = 0;
else
}
else if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)
rc = 0;
else
return rc;
}
#ifdef TESTMODE
static HANDLE openDriver(void)
{
NULL,
NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
}
return hDevice;
}
{
return 0;
}
static int performTest(void)
{
int rc = 0;
if (hDevice != INVALID_HANDLE_VALUE)
else
printf("openDriver failed!\n");
return rc;
}
#endif /* TESTMODE */
static int usage(char *programName)
{
return 1;
}
{
bool installMode;
#ifdef TESTMODE
bool testMode = false;
#endif
if (argc != 2)
installMode = true;
installMode = false;
#ifdef TESTMODE
testMode = true;
#endif
else
int rc;
#ifdef TESTMODE
if (testMode)
rc = performTest();
else
#endif
if (installMode)
rc = installDriver();
else
rc = uninstallDriver();
if (rc == 0)
printf("operation completed successfully!\n");
else
return rc;
}