| 1 |
/* |
| 2 |
* $Id: uninstall.c,v 1.3 2003/01/23 15:16:35 telka Exp $ |
| 3 |
* |
| 4 |
* Copyright (C) 2002 ETC s.r.o. |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU General Public License |
| 8 |
* as published by the Free Software Foundation; either version 2 |
| 9 |
* of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 |
* 02111-1307, USA. |
| 20 |
* |
| 21 |
* Written by Marcel Telka <[email protected]>, 2002. |
| 22 |
* |
| 23 |
*/ |
| 24 |
|
| 25 |
#include <windows.h> |
| 26 |
#include <stdio.h> |
| 27 |
|
| 28 |
void start( int, const char * ); |
| 29 |
void err( int, const char * ); |
| 30 |
void ok( int ); |
| 31 |
|
| 32 |
int |
| 33 |
uninstall( int verb ) |
| 34 |
{ |
| 35 |
SC_HANDLE scm; |
| 36 |
SC_HANDLE svc; |
| 37 |
SERVICE_STATUS stat; |
| 38 |
|
| 39 |
if (verb) |
| 40 |
printf( "Uninstalling ioperm.sys...\n" ); |
| 41 |
|
| 42 |
start( verb, "OpenSCManager" ); |
| 43 |
scm = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS ); |
| 44 |
if (scm == NULL) { |
| 45 |
err( verb, "OpenSCManager" ); |
| 46 |
return 0; |
| 47 |
} |
| 48 |
ok( verb ); |
| 49 |
|
| 50 |
start( verb, "OpenService" ); |
| 51 |
svc = OpenService( scm, TEXT("ioperm"), SERVICE_ALL_ACCESS ); |
| 52 |
if (svc == NULL) { |
| 53 |
if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) |
| 54 |
err( verb, "OpenService" ); |
| 55 |
else { |
| 56 |
if (verb) |
| 57 |
printf( "failed\n" ); |
| 58 |
printf( "ioperm.sys is not installed.\n" ); |
| 59 |
CloseServiceHandle( scm ); |
| 60 |
return 1; |
| 61 |
} |
| 62 |
CloseServiceHandle( scm ); |
| 63 |
return 0; |
| 64 |
} |
| 65 |
ok( verb ); |
| 66 |
|
| 67 |
start( verb, "DeleteService" ); |
| 68 |
if (!DeleteService( svc )) { |
| 69 |
err( verb, "DeleteService" ); |
| 70 |
|
| 71 |
CloseServiceHandle( svc ); |
| 72 |
CloseServiceHandle( scm ); |
| 73 |
return 0; |
| 74 |
} |
| 75 |
ok( verb ); |
| 76 |
|
| 77 |
start( verb, "ControlService" ); |
| 78 |
if (!ControlService( svc, SERVICE_CONTROL_STOP, &stat )) { |
| 79 |
if (GetLastError() != ERROR_SERVICE_NOT_ACTIVE) |
| 80 |
err( verb, "ControlService" ); |
| 81 |
else { |
| 82 |
if (verb) |
| 83 |
printf( "failed\n" ); |
| 84 |
printf( "ioperm.sys is not running.\n" ); |
| 85 |
} |
| 86 |
} else |
| 87 |
ok( verb ); |
| 88 |
|
| 89 |
CloseServiceHandle( svc ); |
| 90 |
CloseServiceHandle( scm ); |
| 91 |
|
| 92 |
return 1; |
| 93 |
} |