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 || dwCurrentState
== SERVICE_STOP_PENDING
44 || dwCurrentState
== SERVICE_STOPPED
)
45 status
.dwControlsAccepted
= 0;
48 status
.dwControlsAccepted
= SERVICE_ACCEPT_STOP
|
49 SERVICE_ACCEPT_PAUSE_CONTINUE
|
50 SERVICE_ACCEPT_SHUTDOWN
;
53 if (dwServiceSpecificExitCode
== 0)
55 status
.dwWin32ExitCode
= dwWin32ExitCode
;
59 status
.dwWin32ExitCode
= ERROR_SERVICE_SPECIFIC_ERROR
;
62 status
.dwServiceSpecificExitCode
= dwServiceSpecificExitCode
;
63 status
.dwCheckPoint
= 0;
64 status
.dwWaitHint
= 0;
66 if (!SetServiceStatus(hstatus
, &status
))
68 fprintf(stderr
, "Failed to set service status\n");
76 static void WINAPI
ServiceCtrlHandler(DWORD code
)
78 WINE_TRACE("%u\n", code
);
82 case SERVICE_CONTROL_SHUTDOWN
:
83 case SERVICE_CONTROL_STOP
:
84 UpdateSCMStatus(SERVICE_STOP_PENDING
, NO_ERROR
, 0);
88 fprintf(stderr
, "Unhandled service control code: %u\n", code
);
89 UpdateSCMStatus(SERVICE_RUNNING
, NO_ERROR
, 0);
94 static DWORD WINAPI
ServiceExecutionThread(LPVOID param
)
96 WaitForSingleObject(kill_event
, INFINITE
);
101 static BOOL
StartServiceThread(void)
105 thread
= CreateThread(0, 0, ServiceExecutionThread
, 0, 0, &id
);
108 fprintf(stderr
, "Failed to create thread\n");
115 static void WINAPI
ServiceMain(DWORD argc
, LPSTR
*argv
)
117 hstatus
= RegisterServiceCtrlHandlerA("MSIServer", ServiceCtrlHandler
);
120 fprintf(stderr
, "Failed to register service ctrl handler\n");
124 UpdateSCMStatus(SERVICE_START_PENDING
, NO_ERROR
, 0);
126 kill_event
= CreateEventW(0, TRUE
, FALSE
, 0);
129 fprintf(stderr
, "Failed to create event\n");
131 UpdateSCMStatus(SERVICE_STOPPED
, NO_ERROR
, 0);
135 if (!StartServiceThread())
138 UpdateSCMStatus(SERVICE_STOPPED
, NO_ERROR
, 0);
142 UpdateSCMStatus(SERVICE_RUNNING
, NO_ERROR
, 0);
143 WaitForSingleObject(thread
, INFINITE
);
144 UpdateSCMStatus(SERVICE_STOPPED
, NO_ERROR
, 0);
147 DWORD
DoService(void)
149 char service_name
[] = "MSIServer";
151 const SERVICE_TABLE_ENTRYA service
[] =
153 {service_name
, ServiceMain
},
157 WINE_TRACE("Starting MSIServer service\n");
159 if (!StartServiceCtrlDispatcherA(service
))
161 fprintf(stderr
, "Failed to start MSIServer service\n");