Mercurial > mplayer.hg
annotate vidix/dhahelperwin/dhasetup.c @ 24819:454f3a34d408
add missing include (errno.h). fix compilation on openbsd
author | ivo |
---|---|
date | Wed, 24 Oct 2007 12:07:29 +0000 |
parents | a36693ffbb17 |
children | a1c020529cc0 |
rev | line source |
---|---|
24542
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
1 /* dhasetup - dhahelper setup program |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
2 * |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
3 * Copyright (c) 2004 - 2007 Sascha Sommer (MPlayer) |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
4 * |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
5 * Some parts from dhasetup.c source code <http://svn.tilp.info/cgi-bin/viewcvs.cgi/libticables/trunk/src/win32/dha/> |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
6 * |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
7 * Copyright (C) 2007 Romain Lievin (tilp) |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
8 * |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
9 * This program is free software; you can redistribute it and/or modify |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
11 * the Free Software Foundation; either version 2 of the License, or |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
12 * (at your option) any later version. |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
13 * |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
17 * GNU General Public License for more details. |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
18 * |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
19 * You should have received a copy of the GNU General Public License |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
20 * along with this program; if not, write to the Free Software |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
22 */ |
12057 | 23 |
24 #include <windows.h> | |
25 #include <stdio.h> | |
24542
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
26 #include <winioctl.h> |
12057 | 27 |
24540 | 28 static void print_last_error(char *s){ |
29 LPTSTR lpMsgBuf; | |
30 | |
31 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | | |
32 FORMAT_MESSAGE_FROM_SYSTEM | | |
33 FORMAT_MESSAGE_IGNORE_INSERTS, | |
34 NULL, GetLastError(), | |
35 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
36 (LPTSTR) & lpMsgBuf, 0, NULL); | |
24542
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
37 if(strlen(lpMsgBuf) >= 2) |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
38 lpMsgBuf[strlen(lpMsgBuf)-2] = 0; |
24540 | 39 |
40 printf("%s (%i -> %s)\n", s, GetLastError(), lpMsgBuf); | |
41 LocalFree(lpMsgBuf); | |
42 } | |
43 | |
12057 | 44 int main(int argc,char* argv[]){ |
24540 | 45 SC_HANDLE hSCManager = NULL; |
46 SC_HANDLE hService = NULL; | |
12058 | 47 char path[MAX_PATH]; |
12057 | 48 printf("dhasetup (c) 2004 Sascha Sommer\n"); |
12098 | 49 GetWindowsDirectory(path,MAX_PATH); |
50 strcpy(path+strlen(path),"\\system32\\drivers\\dhahelper.sys"); | |
12057 | 51 if(argc==1){ |
12098 | 52 printf("Usage:\n"); |
53 printf("dhasetup install - Copies dhahelper.sys from the current directory to\n%s and configures it to start at boot.\n", path); | |
54 printf("dhasetup remove - Removes the dhahelper utility.\n"); | |
12057 | 55 return 0; |
56 } | |
57 hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); | |
58 if(!strcmp(argv[1],"install")){ | |
24540 | 59 printf("Installing dhahelper..."); |
12453 | 60 if(!CopyFile("dhahelper.sys",path,FALSE)){ |
12098 | 61 printf("Copying dhahelper.sys failed.\nEither dhahelper.sys is not in the current directory or you lack sufficient\nprivileges to write to %s.", path); |
62 return 1; | |
12453 | 63 } |
12057 | 64 // Install the driver |
65 hService = CreateService(hSCManager, | |
66 "DHAHELPER", | |
67 "DHAHELPER", | |
68 SERVICE_ALL_ACCESS, | |
69 SERVICE_KERNEL_DRIVER, | |
70 SERVICE_SYSTEM_START, | |
71 SERVICE_ERROR_NORMAL, | |
12058 | 72 path, |
12057 | 73 NULL, |
74 NULL, | |
75 NULL, | |
76 NULL, | |
77 NULL); | |
12450 | 78 if(!hService){ |
24540 | 79 print_last_error("Unable to register DhaHelper Service"); |
80 return 1; | |
12450 | 81 } |
24542
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
82 |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
83 if(!StartService(hService, 0, NULL)){ |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
84 print_last_error("Error while starting service"); |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
85 return 1; |
a36693ffbb17
it is no longer necessary to reboot the system after the dhahelperwin installation (based on code by Romain Lievin from the tilp project)
faust3
parents:
24540
diff
changeset
|
86 } |
24540 | 87 |
88 printf("Success!\n"); | |
12057 | 89 } |
90 else if(!strcmp(argv[1],"remove")){ | |
91 SERVICE_STATUS ServiceStatus; | |
24540 | 92 |
93 printf("Removing dhahelper... "); | |
12057 | 94 hService = OpenService(hSCManager, "DHAHELPER", SERVICE_ALL_ACCESS); |
24540 | 95 if(!hService){ |
96 print_last_error("Error opening dhahelper service"); | |
97 return 1; | |
98 } | |
99 if(!ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus)) | |
100 print_last_error("Error while stopping service"); | |
101 if(!DeleteService(hService)) | |
102 print_last_error("Error while deleting service"); | |
12058 | 103 DeleteFile(path); |
24540 | 104 printf("Done!\n"); |
12057 | 105 } |
106 else { | |
107 printf("unknown parameter: %s\n",argv[1]); | |
108 } | |
109 CloseServiceHandle(hService); | |
110 CloseServiceHandle(hSCManager); | |
111 return 0; | |
112 } |