#include <stdlib.h>
#include <strsafe.h>
#include <wtsapi32.h>
+#include <cfgmgr32.h>
#include <malloc.h>
#include <assert.h>
#include <version.h>
#include "messages.h"
-#include "strings.h"
#define MONITOR_NAME __MODULE__
#define MONITOR_DISPLAYNAME MONITOR_NAME
HANDLE StopEvent;
HANDLE RequestEvent;
HKEY RequestKey;
+ PTCHAR Title;
+ PTCHAR Message;
BOOL RebootPending;
} MONITOR_CONTEXT, *PMONITOR_CONTEXT;
VOID
)
{
+ Log("waiting for pending install events...");
+
+ (VOID) CM_WaitNoPendingInstallEvents(INFINITE);
+
+ Log("initiating shutdown...");
+
(VOID) InitiateSystemShutdownEx(NULL,
NULL,
0,
)
{
PMONITOR_CONTEXT Context = &MonitorContext;
+ PTCHAR Title;
+ DWORD TitleLength;
HRESULT Result;
TCHAR ServiceKeyName[MAX_PATH];
HKEY ServiceKey;
DWORD MaxValueLength;
DWORD DisplayNameLength;
PTCHAR DisplayName;
- PTCHAR Description;
DWORD Type;
- TCHAR Title[] = TEXT(VENDOR_NAME_STR);
- TCHAR Message[MAXIMUM_BUFFER_SIZE];
- DWORD Length;
+ PTCHAR Description;
+ PTCHAR Message;
+ DWORD MessageLength;
PWTS_SESSION_INFO SessionInfo;
DWORD Count;
DWORD Index;
Log("====> (%s)", DriverName);
+ Title = Context->Title;
+ TitleLength = (DWORD)((_tcslen(Context->Title) +
+ 1) * sizeof (TCHAR));
+
Result = StringCbPrintf(ServiceKeyName,
MAX_PATH,
SERVICES_KEY "\\%s",
else
Description++;
- Result = StringCbPrintf(Message,
- MAXIMUM_BUFFER_SIZE,
- TEXT("%s "),
- Description);
- assert(SUCCEEDED(Result));
+ MessageLength = (DWORD)((_tcslen(Description) +
+ 1 + // ' '
+ _tcslen(Context->Message) +
+ 1) * sizeof (TCHAR));
- Length = (DWORD)_tcslen(Message);
-
- Length = LoadString(GetModuleHandle(NULL),
- IDS_DIALOG,
- Message + Length,
- ARRAYSIZE(Message) - Length);
- if (Length == 0)
+ Message = calloc(1, MessageLength);
+ if (Message == NULL)
goto fail6;
+ Result = StringCbPrintf(Message,
+ MessageLength,
+ TEXT("%s %s"),
+ Description,
+ Context->Message);
+ assert(SUCCEEDED(Result));
+
Success = WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE,
0,
1,
&SessionInfo,
&Count);
-
if (!Success)
goto fail7;
Success = WTSSendMessage(WTS_CURRENT_SERVER_HANDLE,
SessionId,
Title,
- sizeof (Title),
+ TitleLength,
Message,
- sizeof (Message),
+ MessageLength,
MB_YESNO | MB_ICONEXCLAMATION,
Timeout,
&Response,
return FALSE;
}
+static BOOL
+GetDialogParameters(
+ VOID
+ )
+{
+ PMONITOR_CONTEXT Context = &MonitorContext;
+ DWORD MaxValueLength;
+ DWORD TitleLength;
+ DWORD MessageLength;
+ DWORD Type;
+ HRESULT Error;
+
+ Error = RegQueryInfoKey(Context->ParametersKey,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ &MaxValueLength,
+ NULL,
+ NULL);
+ if (Error != ERROR_SUCCESS) {
+ SetLastError(Error);
+ goto fail1;
+ }
+
+ TitleLength = MaxValueLength + sizeof (TCHAR);
+
+ Context->Title = calloc(1, TitleLength);
+ if (Context == NULL)
+ goto fail2;
+
+ Error = RegQueryValueEx(Context->ParametersKey,
+ "DialogTitle",
+ NULL,
+ &Type,
+ (LPBYTE)Context->Title,
+ &TitleLength);
+ if (Error != ERROR_SUCCESS) {
+ SetLastError(Error);
+ goto fail3;
+ }
+
+ if (Type != REG_SZ) {
+ SetLastError(ERROR_BAD_FORMAT);
+ goto fail4;
+ }
+
+ MessageLength = MaxValueLength + sizeof (TCHAR);
+
+ Context->Message = calloc(1, MessageLength);
+ if (Context == NULL)
+ goto fail5;
+
+ Error = RegQueryValueEx(Context->ParametersKey,
+ "DialogMessage",
+ NULL,
+ &Type,
+ (LPBYTE)Context->Message,
+ &MessageLength);
+ if (Error != ERROR_SUCCESS) {
+ SetLastError(Error);
+ goto fail6;
+ }
+
+ if (Type != REG_SZ) {
+ SetLastError(ERROR_BAD_FORMAT);
+ goto fail7;
+ }
+
+ return TRUE;
+
+fail7:
+ Log("fail7");
+
+fail6:
+ Log("fail6");
+
+ free(Context->Message);
+
+fail5:
+ Log("fail5");
+
+fail4:
+ Log("fail4");
+
+fail3:
+ Log("fail3");
+
+ free(Context->Title);
+
+fail2:
+ Log("fail2");
+
+fail1:
+ Error = GetLastError();
+
+ {
+ PTCHAR Message;
+ Message = GetErrorMessage(Error);
+ Log("fail1 (%s)", Message);
+ LocalFree(Message);
+ }
+
+ return FALSE;
+}
+
+
+
VOID WINAPI
MonitorMain(
_In_ DWORD argc,
if (Error != ERROR_SUCCESS)
goto fail8;
+ Success = GetDialogParameters();
+ if (!Success)
+ goto fail9;
+
SetEvent(Context->RequestEvent);
ReportStatus(SERVICE_RUNNING, NO_ERROR, 0);
done:
(VOID) RegDeleteTree(Context->RequestKey, NULL);
+ free(Context->Message);
+ free(Context->Title);
CloseHandle(Context->RequestKey);
+ free(RequestKeyName);
CloseHandle(Context->RequestEvent);
CloseHandle(Context->StopEvent);
return;
+fail9:
+ Log("fail9");
+
+ CloseHandle(Context->RequestKey);
+
fail8:
Log("fail8");
+++ /dev/null
-/* Copyright (c) Citrix Systems Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms,
- * with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the
- * following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _MONITOR_STRINGS_H_
-#define _MONITOR_STRINGS_H_
-
-#define IDS_DIALOG 1
-
-#endif // _MONITOR_STRINGS_H_
+++ /dev/null
-/* Copyright (c) Citrix Systems Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms,
- * with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the
- * following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "strings.h"
-
-STRINGTABLE
-{
- IDS_DIALOG, "needs to restart the system to complete installation.\nPress 'Yes' to restart the system now or 'No' if you plan to restart the system later."
-}
\ No newline at end of file
#include "common.ver"
#include "messages.rc"
-#include "strings.rc"
[Monitor_Parameters]
HKR,"Parameters",,0x00000010
HKR,"Parameters","RequestKey",0x00000000,%RequestKey%
+HKR,"Parameters","DialogTitle",0x00000000,%DialogTitle%
+HKR,"Parameters","DialogMessage",0x00000000,%DialogMessage%
[Monitor_Request]
HKLM,%RequestKey% ,,0x00000010
MonitorName="@PRODUCT_NAME@ PV Driver Monitor"
MonitorDesc="Provides support for @PRODUCT_NAME@ PV drivers"
RequestKey="SOFTWARE\@VENDOR_NAME@\@PRODUCT_NAME@\PV Driver Monitor\Request"
+DialogTitle="@PRODUCT_NAME@"
+DialogMessage="needs to restart the system to complete installation. Press 'Yes' to restart the system now or 'No' if you plan to restart the system later."
SERVICE_BOOT_START=0x0
SERVICE_SYSTEM_START=0x1
<RuntimeLibrary Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
- <AdditionalDependencies>wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wtsapi32.lib;cfgmgr32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
- <AdditionalDependencies>wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>wtsapi32.lib;cfgmgr32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>