2008-05-13 08:36:44 +00:00
|
|
|
/*
|
|
|
|
* dhasetup - dhahelper setup program
|
2007-09-17 21:53:16 +00:00
|
|
|
*
|
2008-05-13 08:36:44 +00:00
|
|
|
* Copyright (c) 2004 - 2007 Sascha Sommer (MPlayer)
|
2007-09-17 21:53:16 +00:00
|
|
|
*
|
2008-05-13 08:36:44 +00:00
|
|
|
* some parts from dhasetup.c source code
|
|
|
|
* http://svn.tilp.info/cgi-bin/viewcvs.cgi/libticables/trunk/src/win32/dha/
|
2007-09-17 21:53:16 +00:00
|
|
|
*
|
2008-05-13 08:36:44 +00:00
|
|
|
* Copyright (C) 2007 Romain Lievin (tilp)
|
2007-09-17 21:53:16 +00:00
|
|
|
*
|
2008-05-13 08:36:44 +00:00
|
|
|
* This file is part of MPlayer.
|
2007-09-17 21:53:16 +00:00
|
|
|
*
|
2008-05-13 08:36:44 +00:00
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2007-09-17 21:53:16 +00:00
|
|
|
*
|
2008-05-13 08:36:44 +00:00
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-09-17 21:53:16 +00:00
|
|
|
*/
|
2004-03-23 10:41:04 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
2007-09-17 21:53:16 +00:00
|
|
|
#include <winioctl.h>
|
2004-03-23 10:41:04 +00:00
|
|
|
|
2007-09-17 21:03:24 +00:00
|
|
|
static void print_last_error(char *s){
|
|
|
|
LPTSTR lpMsgBuf;
|
|
|
|
|
|
|
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL, GetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
|
(LPTSTR) & lpMsgBuf, 0, NULL);
|
2007-09-17 21:53:16 +00:00
|
|
|
if(strlen(lpMsgBuf) >= 2)
|
|
|
|
lpMsgBuf[strlen(lpMsgBuf)-2] = 0;
|
2007-09-17 21:03:24 +00:00
|
|
|
|
|
|
|
printf("%s (%i -> %s)\n", s, GetLastError(), lpMsgBuf);
|
|
|
|
LocalFree(lpMsgBuf);
|
|
|
|
}
|
|
|
|
|
2004-03-23 10:41:04 +00:00
|
|
|
int main(int argc,char* argv[]){
|
2007-09-17 21:03:24 +00:00
|
|
|
SC_HANDLE hSCManager = NULL;
|
|
|
|
SC_HANDLE hService = NULL;
|
2004-03-23 12:43:54 +00:00
|
|
|
char path[MAX_PATH];
|
2004-03-23 10:41:04 +00:00
|
|
|
printf("dhasetup (c) 2004 Sascha Sommer\n");
|
2004-04-01 22:48:37 +00:00
|
|
|
GetWindowsDirectory(path,MAX_PATH);
|
|
|
|
strcpy(path+strlen(path),"\\system32\\drivers\\dhahelper.sys");
|
2004-03-23 10:41:04 +00:00
|
|
|
if(argc==1){
|
2004-04-01 22:48:37 +00:00
|
|
|
printf("Usage:\n");
|
|
|
|
printf("dhasetup install - Copies dhahelper.sys from the current directory to\n%s and configures it to start at boot.\n", path);
|
|
|
|
printf("dhasetup remove - Removes the dhahelper utility.\n");
|
2004-03-23 10:41:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
|
|
|
if(!strcmp(argv[1],"install")){
|
2007-09-17 21:03:24 +00:00
|
|
|
printf("Installing dhahelper...");
|
2004-05-09 17:36:44 +00:00
|
|
|
if(!CopyFile("dhahelper.sys",path,FALSE)){
|
2004-04-01 22:48:37 +00:00
|
|
|
printf("Copying dhahelper.sys failed.\nEither dhahelper.sys is not in the current directory or you lack sufficient\nprivileges to write to %s.", path);
|
|
|
|
return 1;
|
2004-05-09 17:36:44 +00:00
|
|
|
}
|
2004-03-23 10:41:04 +00:00
|
|
|
// Install the driver
|
|
|
|
hService = CreateService(hSCManager,
|
|
|
|
"DHAHELPER",
|
|
|
|
"DHAHELPER",
|
|
|
|
SERVICE_ALL_ACCESS,
|
|
|
|
SERVICE_KERNEL_DRIVER,
|
|
|
|
SERVICE_SYSTEM_START,
|
|
|
|
SERVICE_ERROR_NORMAL,
|
2004-03-23 12:43:54 +00:00
|
|
|
path,
|
2004-03-23 10:41:04 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2004-05-09 14:03:10 +00:00
|
|
|
if(!hService){
|
2007-09-17 21:03:24 +00:00
|
|
|
print_last_error("Unable to register DhaHelper Service");
|
|
|
|
return 1;
|
2004-05-09 14:03:10 +00:00
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2007-09-17 21:53:16 +00:00
|
|
|
if(!StartService(hService, 0, NULL)){
|
|
|
|
print_last_error("Error while starting service");
|
|
|
|
return 1;
|
|
|
|
}
|
2007-09-17 21:03:24 +00:00
|
|
|
|
|
|
|
printf("Success!\n");
|
2004-03-23 10:41:04 +00:00
|
|
|
}
|
|
|
|
else if(!strcmp(argv[1],"remove")){
|
|
|
|
SERVICE_STATUS ServiceStatus;
|
2007-09-17 21:03:24 +00:00
|
|
|
|
|
|
|
printf("Removing dhahelper... ");
|
2004-03-23 10:41:04 +00:00
|
|
|
hService = OpenService(hSCManager, "DHAHELPER", SERVICE_ALL_ACCESS);
|
2007-09-17 21:03:24 +00:00
|
|
|
if(!hService){
|
|
|
|
print_last_error("Error opening dhahelper service");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if(!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus))
|
|
|
|
print_last_error("Error while stopping service");
|
|
|
|
if(!DeleteService(hService))
|
|
|
|
print_last_error("Error while deleting service");
|
2004-03-23 12:43:54 +00:00
|
|
|
DeleteFile(path);
|
2007-09-17 21:03:24 +00:00
|
|
|
printf("Done!\n");
|
2004-03-23 10:41:04 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("unknown parameter: %s\n",argv[1]);
|
|
|
|
}
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
CloseServiceHandle(hSCManager);
|
|
|
|
return 0;
|
|
|
|
}
|