2 * msiexec.exe implementation
4 * Copyright 2007 Google (James Hawkins)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 static SERVICE_STATUS_HANDLE hstatus
;
26 static HANDLE kill_event
;
28 static void KillService(void)
30 WINE_TRACE("Killing service\n");
34 static BOOL
UpdateSCMStatus(DWORD dwCurrentState
, DWORD dwWin32ExitCode
,
35 DWORD dwServiceSpecificExitCode
)
37 SERVICE_STATUS status
;
39 status
.dwServiceType
= SERVICE_WIN32_OWN_PROCESS
;
40 status
.dwCurrentState
= dwCurrentState
;
42 if (dwCurrentState
== SERVICE_START_PENDING
)
43 status
.dwControlsAccepted
= 0;
46 status
.dwControlsAccepted
= SERVICE_ACCEPT_STOP
|
47 SERVICE_ACCEPT_PAUSE_CONTINUE
|
48 SERVICE_ACCEPT_SHUTDOWN
;
51 if (dwServiceSpecificExitCode
== 0)
53 status
.dwWin32ExitCode
= dwWin32ExitCode
;
57 status
.dwWin32ExitCode
= ERROR_SERVICE_SPECIFIC_ERROR
;
60 status
.dwServiceSpecificExitCode
= dwServiceSpecificExitCode
;
61 status
.dwCheckPoint
= 0;
62 status
.dwWaitHint
= 0;
64 if (!SetServiceStatus(hstatus
, &status
))
66 fprintf(stderr
, "Failed to set service status\n");
74 static void WINAPI
ServiceCtrlHandler(DWORD code
)
76 WINE_TRACE("%u\n", code
);
80 case SERVICE_CONTROL_SHUTDOWN
:
81 case SERVICE_CONTROL_STOP
:
82 UpdateSCMStatus(SERVICE_STOP_PENDING
, NO_ERROR
, 0);
86 fprintf(stderr
, "Unhandled service control code: %u\n", code
);
90 UpdateSCMStatus(SERVICE_RUNNING
, NO_ERROR
, 0);
93 static DWORD WINAPI
ServiceExecutionThread(LPVOID param
)
103 static BOOL
StartServiceThread(void)
107 thread
= CreateThread(0, 0, ServiceExecutionThread
, 0, 0, &id
);
110 fprintf(stderr
, "Failed to create thread\n");
117 static void WINAPI
ServiceMain(DWORD argc
, LPSTR
*argv
)
119 hstatus
= RegisterServiceCtrlHandlerA("MSIServer", ServiceCtrlHandler
);
122 fprintf(stderr
, "Failed to register service ctrl handler\n");
126 UpdateSCMStatus(SERVICE_START_PENDING
, NO_ERROR
, 0);
128 kill_event
= CreateEventW(0, TRUE
, FALSE
, 0);
131 fprintf(stderr
, "Failed to create event\n");
136 if (!StartServiceThread())
142 UpdateSCMStatus(SERVICE_RUNNING
, NO_ERROR
, 0);
144 WaitForSingleObject(kill_event
, INFINITE
);
148 DWORD
DoService(void)
150 char service_name
[] = "MSIServer";
152 const SERVICE_TABLE_ENTRYA service
[] =
154 {service_name
, ServiceMain
},
158 WINE_TRACE("Starting MSIServer service\n");
160 if (!StartServiceCtrlDispatcherA(service
))
162 fprintf(stderr
, "Failed to start MSIServer service\n");