manpage: document -playlist being unsafe in its option description
[mplayer/glamo.git] / vidix / dhahelperwin / dhasetup.c
blob8642fa490cc855605882847016e771c12e5b1a03
1 /*
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.
28 #include <windows.h>
29 #include <stdio.h>
30 #include <winioctl.h>
32 static void print_last_error(char *s){
33 LPTSTR lpMsgBuf;
35 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
36 FORMAT_MESSAGE_FROM_SYSTEM |
37 FORMAT_MESSAGE_IGNORE_INSERTS,
38 NULL, GetLastError(),
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);
45 LocalFree(lpMsgBuf);
48 int main(int argc,char* argv[]){
49 SC_HANDLE hSCManager = NULL;
50 SC_HANDLE hService = NULL;
51 char path[MAX_PATH];
52 printf("dhasetup (c) 2004 Sascha Sommer\n");
53 GetWindowsDirectory(path,MAX_PATH);
54 strcpy(path+strlen(path),"\\system32\\drivers\\dhahelper.sys");
55 if(argc==1){
56 printf("Usage:\n");
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");
59 return 0;
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);
66 return 1;
68 // Install the driver
69 hService = CreateService(hSCManager,
70 "DHAHELPER",
71 "DHAHELPER",
72 SERVICE_ALL_ACCESS,
73 SERVICE_KERNEL_DRIVER,
74 SERVICE_SYSTEM_START,
75 SERVICE_ERROR_NORMAL,
76 path,
77 NULL,
78 NULL,
79 NULL,
80 NULL,
81 NULL);
82 if(!hService){
83 print_last_error("Unable to register DhaHelper Service");
84 return 1;
87 if(!StartService(hService, 0, NULL)){
88 print_last_error("Error while starting service");
89 return 1;
92 printf("Success!\n");
94 else if(!strcmp(argv[1],"remove")){
95 SERVICE_STATUS ServiceStatus;
97 printf("Removing dhahelper... ");
98 hService = OpenService(hSCManager, "DHAHELPER", SERVICE_ALL_ACCESS);
99 if(!hService){
100 print_last_error("Error opening dhahelper service");
101 return 1;
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");
107 DeleteFile(path);
108 printf("Done!\n");
110 else {
111 printf("unknown parameter: %s\n",argv[1]);
113 CloseServiceHandle(hService);
114 CloseServiceHandle(hSCManager);
115 return 0;