2 * dhasetup - dhahelper setup program
4 * Copyright (c) 2004 - 2007 Sascha Sommer (MPlayer)
6 * some parts from dhasetup.c source code
7 * http://svn.tilp.info/cgi-bin/viewcvs.cgi/libticables/trunk/src/win32/dha/
9 * Copyright (C) 2007 Romain Lievin (tilp)
11 * This file is part of MPlayer.
13 * MPlayer is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * MPlayer is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 static void print_last_error(char *s
){
35 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
36 FORMAT_MESSAGE_FROM_SYSTEM
|
37 FORMAT_MESSAGE_IGNORE_INSERTS
,
39 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
40 (LPTSTR
) & lpMsgBuf
, 0, NULL
);
41 if(strlen(lpMsgBuf
) >= 2)
42 lpMsgBuf
[strlen(lpMsgBuf
)-2] = 0;
44 printf("%s (%i -> %s)\n", s
, GetLastError(), lpMsgBuf
);
48 int main(int argc
,char* argv
[]){
49 SC_HANDLE hSCManager
= NULL
;
50 SC_HANDLE hService
= NULL
;
52 printf("dhasetup (c) 2004 Sascha Sommer\n");
53 GetWindowsDirectory(path
,MAX_PATH
);
54 strcpy(path
+strlen(path
),"\\system32\\drivers\\dhahelper.sys");
57 printf("dhasetup install - Copies dhahelper.sys from the current directory to\n%s and configures it to start at boot.\n", path
);
58 printf("dhasetup remove - Removes the dhahelper utility.\n");
61 hSCManager
= OpenSCManager(NULL
, NULL
, SC_MANAGER_ALL_ACCESS
);
62 if(!strcmp(argv
[1],"install")){
63 printf("Installing dhahelper...");
64 if(!CopyFile("dhahelper.sys",path
,FALSE
)){
65 printf("Copying dhahelper.sys failed.\nEither dhahelper.sys is not in the current directory or you lack sufficient\nprivileges to write to %s.", path
);
69 hService
= CreateService(hSCManager
,
73 SERVICE_KERNEL_DRIVER
,
83 print_last_error("Unable to register DhaHelper Service");
87 if(!StartService(hService
, 0, NULL
)){
88 print_last_error("Error while starting service");
94 else if(!strcmp(argv
[1],"remove")){
95 SERVICE_STATUS ServiceStatus
;
97 printf("Removing dhahelper... ");
98 hService
= OpenService(hSCManager
, "DHAHELPER", SERVICE_ALL_ACCESS
);
100 print_last_error("Error opening dhahelper service");
103 if(!ControlService(hService
, SERVICE_CONTROL_STOP
, &ServiceStatus
))
104 print_last_error("Error while stopping service");
105 if(!DeleteService(hService
))
106 print_last_error("Error while deleting service");
111 printf("unknown parameter: %s\n",argv
[1]);
113 CloseServiceHandle(hService
);
114 CloseServiceHandle(hSCManager
);