summaryrefslogtreecommitdiff
path: root/inject
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2014-09-10 13:22:56 +0100
committerJosé Fonseca <jfonseca@vmware.com>2014-09-10 23:11:03 +0100
commit1d3ac85a6dd2cb7518df8310f28787443c0bc3bf (patch)
tree3957b92f2a14019a9fcb0db50dec4944d79da012 /inject
parent7ad09391896bd02d976cbadbea40aa5ec1e132b5 (diff)
inject: Restart DWM service after tracing.
Diffstat (limited to 'inject')
-rw-r--r--inject/injector.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/inject/injector.cpp b/inject/injector.cpp
index 886cd4d8..f5de9e20 100644
--- a/inject/injector.cpp
+++ b/inject/injector.cpp
@@ -114,6 +114,45 @@ quoteArg(std::string &s, const char *arg)
}
+// http://msdn.microsoft.com/en-gb/library/windows/desktop/ms686335.aspx
+static void
+restartService(const char *lpServiceName)
+{
+ fprintf(stderr, "info: restarting %s\n", lpServiceName);
+
+ SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ assert(hSCManager);
+ if (!hSCManager) {
+ return;
+ }
+
+ SC_HANDLE hService = OpenServiceA(hSCManager, lpServiceName, SC_MANAGER_ALL_ACCESS);
+ assert(hService);
+ if (!hService) {
+ return;
+ }
+
+ SERVICE_STATUS_PROCESS ssp;
+ DWORD cbBytesNeeded;
+ QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, (LPBYTE) &ssp, sizeof ssp, &cbBytesNeeded);
+
+ BOOL bRet;
+ if (ssp.dwCurrentState == SERVICE_RUNNING) {
+ bRet = ControlService(hService, SERVICE_CONTROL_STOP, (LPSERVICE_STATUS) &ssp);
+ assert(bRet);
+ while (ssp.dwCurrentState != SERVICE_STOPPED) {
+ Sleep(ssp.dwWaitHint);
+ QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, (LPBYTE) &ssp, sizeof ssp, &cbBytesNeeded);
+ }
+ bRet = StartService(hService, 0, NULL);
+ assert(bRet);
+ }
+
+ CloseServiceHandle(hService);
+ CloseServiceHandle(hSCManager);
+}
+
+
// XXX: This doesn't work on Windows 8 onwards
static void
restartDwmComposition(void)
@@ -159,6 +198,14 @@ restartDwmComposition(void)
hr = pfnDwmEnableComposition(DWM_EC_ENABLECOMPOSITION);
assert(SUCCEEDED(hr));
(void)hr;
+
+ fprintf(stderr, "Press a key when ready\n");
+ getchar();
+
+ hr = pfnDwmEnableComposition(DWM_EC_DISABLECOMPOSITION);
+ assert(SUCCEEDED(hr));
+
+ restartService("uxsms");
}