#include "qemu/systemd.h"
#include "qemu-version.h"
#ifdef _WIN32
+#include <windows.h>
+#include <objbase.h>
#include <dbt.h>
#include <pdh.h>
#include "qga/service-win32.h"
return ret;
}
+/* Initialize COM for VSS operations */
+static HRESULT init_com(void)
+{
+ HRESULT hr;
+
+ hr = CoInitialize(NULL);
+ if (FAILED(hr)) {
+ return hr;
+ }
+
+ hr = CoInitializeSecurity(
+ NULL, -1, NULL, NULL,
+ RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
+ RPC_C_IMP_LEVEL_IDENTIFY,
+ NULL, EOAC_NONE, NULL);
+ if (FAILED(hr)) {
+ CoUninitialize();
+ return hr;
+ }
+
+ return S_OK;
+}
+
VOID WINAPI service_main(DWORD argc, TCHAR *argv[])
{
GAService *service = &ga_state->service;
return;
}
+ /* Initialize COM for VSS operations in the service thread */
+ HRESULT hr_com = init_com();
+ if (FAILED(hr_com)) {
+ g_critical("Failed to initialize COM in service thread: 0x%lx", hr_com);
+ return;
+ }
+
service->status.dwServiceType = SERVICE_WIN32;
service->status.dwCurrentState = SERVICE_RUNNING;
service->status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
run_agent(ga_state);
+ CoUninitialize();
+
UnregisterDeviceNotification(service->device_notification_handle);
service->status.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus(service->status_handle, &service->status);
StartServiceCtrlDispatcher(service_table);
ret = EXIT_SUCCESS;
} else {
+ HRESULT hr_com = init_com();
+ if (FAILED(hr_com)) {
+ g_critical("Failed to initialize COM: 0x%lx", hr_com);
+ ret = EXIT_FAILURE;
+ goto end;
+ }
+
ret = run_agent(s);
+ CoUninitialize();
}
#else
ret = run_agent(s);
{
qga_debug_begin;
- COMInitializer initializer; /* to call CoInitializeSecurity */
- HRESULT hr = CoInitializeSecurity(
- NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
- RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, NULL);
- if (FAILED(hr)) {
- qga_debug("failed to CoInitializeSecurity (error %lx)", hr);
- return hr;
- }
-
hLib = LoadLibraryA("VSSAPI.DLL");
if (!hLib) {
qga_debug("failed to load VSSAPI.DLL");
return;
}
- CoInitialize(NULL);
-
/* Allow unrestricted access to events */
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
out1:
requester_cleanup();
- CoUninitialize();
qga_debug_end;
}
*num_vols = vss_ctx.cFrozenVols;
requester_cleanup();
- CoUninitialize();
StopService();
qga_debug_end;