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
21 #define WIN32_LEAN_AND_MEAN
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msiexec
);
31 static SERVICE_STATUS_HANDLE hstatus
;
34 static HANDLE kill_event
;
36 static void KillService(void)
38 WINE_TRACE("Killing service\n");
42 static BOOL
UpdateSCMStatus(DWORD dwCurrentState
, DWORD dwWin32ExitCode
,
43 DWORD dwServiceSpecificExitCode
)
45 SERVICE_STATUS status
;
47 status
.dwServiceType
= SERVICE_WIN32_OWN_PROCESS
;
48 status
.dwCurrentState
= dwCurrentState
;
50 if (dwCurrentState
== SERVICE_START_PENDING
51 || dwCurrentState
== SERVICE_STOP_PENDING
52 || dwCurrentState
== SERVICE_STOPPED
)
53 status
.dwControlsAccepted
= 0;
56 status
.dwControlsAccepted
= SERVICE_ACCEPT_STOP
|
57 SERVICE_ACCEPT_PAUSE_CONTINUE
|
58 SERVICE_ACCEPT_SHUTDOWN
;
61 if (dwServiceSpecificExitCode
== 0)
63 status
.dwWin32ExitCode
= dwWin32ExitCode
;
67 status
.dwWin32ExitCode
= ERROR_SERVICE_SPECIFIC_ERROR
;
70 status
.dwServiceSpecificExitCode
= dwServiceSpecificExitCode
;
71 status
.dwCheckPoint
= 0;
72 status
.dwWaitHint
= 0;
74 if (!SetServiceStatus(hstatus
, &status
))
76 fprintf(stderr
, "Failed to set service status\n");
84 static void WINAPI
ServiceCtrlHandler(DWORD code
)
86 WINE_TRACE("%d\n", code
);
90 case SERVICE_CONTROL_SHUTDOWN
:
91 case SERVICE_CONTROL_STOP
:
92 UpdateSCMStatus(SERVICE_STOP_PENDING
, NO_ERROR
, 0);
96 fprintf(stderr
, "Unhandled service control code: %d\n", code
);
97 UpdateSCMStatus(SERVICE_RUNNING
, NO_ERROR
, 0);
102 static DWORD WINAPI
ServiceExecutionThread(LPVOID param
)
104 WaitForSingleObject(kill_event
, INFINITE
);
109 static BOOL
StartServiceThread(void)
113 thread
= CreateThread(0, 0, ServiceExecutionThread
, 0, 0, &id
);
116 fprintf(stderr
, "Failed to create thread\n");
123 static void WINAPI
ServiceMain(DWORD argc
, LPSTR
*argv
)
125 hstatus
= RegisterServiceCtrlHandlerA("MSIServer", ServiceCtrlHandler
);
128 fprintf(stderr
, "Failed to register service ctrl handler\n");
132 UpdateSCMStatus(SERVICE_START_PENDING
, NO_ERROR
, 0);
134 kill_event
= CreateEventW(0, TRUE
, FALSE
, 0);
137 fprintf(stderr
, "Failed to create event\n");
139 UpdateSCMStatus(SERVICE_STOPPED
, NO_ERROR
, 0);
143 if (!StartServiceThread())
146 UpdateSCMStatus(SERVICE_STOPPED
, NO_ERROR
, 0);
150 UpdateSCMStatus(SERVICE_RUNNING
, NO_ERROR
, 0);
151 WaitForSingleObject(thread
, INFINITE
);
152 UpdateSCMStatus(SERVICE_STOPPED
, NO_ERROR
, 0);
155 DWORD
DoService(void)
157 char service_name
[] = "MSIServer";
159 const SERVICE_TABLE_ENTRYA service
[] =
161 {service_name
, ServiceMain
},
165 WINE_TRACE("Starting MSIServer service\n");
167 if (!StartServiceCtrlDispatcherA(service
))
169 fprintf(stderr
, "Failed to start MSIServer service\n");