HKEY RequestKey;
PTCHAR Title;
PTCHAR Text;
+ PTCHAR Question;
BOOL RebootPending;
} MONITOR_CONTEXT, *PMONITOR_CONTEXT;
return Value;
}
-static VOID
-PromptForReboot(
+static PTCHAR
+GetDisplayName(
IN PTCHAR DriverName
)
{
- PMONITOR_CONTEXT Context = &MonitorContext;
- PTCHAR Title;
- DWORD TitleLength;
HRESULT Result;
TCHAR ServiceKeyName[MAX_PATH];
HKEY ServiceKey;
DWORD MaxValueLength;
+ DWORD Type;
DWORD DisplayNameLength;
PTCHAR DisplayName;
- DWORD Type;
- PTCHAR Description;
- PTCHAR Text;
- DWORD TextLength;
- PWTS_SESSION_INFO SessionInfo;
- DWORD Count;
- DWORD Index;
- BOOL Success;
HRESULT Error;
- Log("====> (%s)", DriverName);
-
- Title = Context->Title;
- TitleLength = (DWORD)((_tcslen(Context->Title) +
- 1) * sizeof (TCHAR));
-
Result = StringCbPrintf(ServiceKeyName,
MAX_PATH,
SERVICES_KEY "\\%s",
goto fail5;
}
+ RegCloseKey(ServiceKey);
+
+ return DisplayName;
+
+fail5:
+ Log("fail5");
+
+fail4:
+ Log("fail4");
+
+ free(DisplayName);
+
+fail3:
+ Log("fail3");
+
+fail2:
+ Log("fail2");
+
+ RegCloseKey(ServiceKey);
+
+fail1:
+ Error = GetLastError();
+
+ {
+ PTCHAR Message;
+ Message = GetErrorMessage(Error);
+ Log("fail1 (%s)", Message);
+ LocalFree(Message);
+ }
+
+ return NULL;
+}
+
+static VOID
+PromptForReboot(
+ IN PTCHAR DriverName
+ )
+{
+ PMONITOR_CONTEXT Context = &MonitorContext;
+ HRESULT Result;
+ PTCHAR Title;
+ DWORD TitleLength;
+ PTCHAR DisplayName;
+ PTCHAR Description;
+ PTCHAR Text;
+ DWORD TextLength;
+ PWTS_SESSION_INFO SessionInfo;
+ DWORD Count;
+ DWORD Index;
+ BOOL Success;
+ HRESULT Error;
+
+ Log("====> (%s)", DriverName);
+
+ Title = Context->Title;
+ TitleLength = (DWORD)((_tcslen(Context->Title) +
+ 1) * sizeof (TCHAR));
+
+ DisplayName = GetDisplayName(DriverName);
+ if (DisplayName == NULL)
+ goto fail1;
+
Description = _tcsrchr(DisplayName, ';');
if (Description == NULL)
Description = DisplayName;
TextLength = (DWORD)((_tcslen(Description) +
1 + // ' '
_tcslen(Context->Text) +
+ 1 + // ' '
+ _tcslen(Context->Question) +
1) * sizeof (TCHAR));
Text = calloc(1, TextLength);
if (Text == NULL)
- goto fail6;
+ goto fail2;
Result = StringCbPrintf(Text,
TextLength,
- TEXT("%s %s"),
+ TEXT("%s %s %s"),
Description,
- Context->Text);
+ Context->Text,
+ Context->Question);
assert(SUCCEEDED(Result));
Success = WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE,
&SessionInfo,
&Count);
if (!Success)
- goto fail7;
+ goto fail3;
for (Index = 0; Index < Count; Index++) {
DWORD SessionId = SessionInfo[Index].SessionId;
TRUE);
if (!Success)
- goto fail8;
+ goto fail4;
Context->RebootPending = TRUE;
free(DisplayName);
- RegCloseKey(ServiceKey);
-
Log("<====");
return;
-fail8:
- Log("fail8");
-
- WTSFreeMemory(SessionInfo);
-
-fail7:
- Log("fail7");
-
-fail6:
- Log("fail6");
-
-fail5:
- Log("fail5");
-
fail4:
Log("fail4");
- free(DisplayName);
+ WTSFreeMemory(SessionInfo);
fail3:
Log("fail3");
fail2:
Log("fail2");
- RegCloseKey(ServiceKey);
+ free(DisplayName);
fail1:
Error = GetLastError();
DWORD MaxValueLength;
DWORD TitleLength;
DWORD TextLength;
+ DWORD QuestionLength;
DWORD Type;
HRESULT Error;
goto fail7;
}
+ QuestionLength = MaxValueLength + sizeof (TCHAR);
+
+ Context->Question = calloc(1, QuestionLength);
+ if (Context == NULL)
+ goto fail8;
+
+ Error = RegQueryValueEx(Context->ParametersKey,
+ "DialogQuestion",
+ NULL,
+ &Type,
+ (LPBYTE)Context->Question,
+ &QuestionLength);
+ if (Error != ERROR_SUCCESS) {
+ SetLastError(Error);
+ goto fail9;
+ }
+
+ if (Type != REG_SZ) {
+ SetLastError(ERROR_BAD_FORMAT);
+ goto fail10;
+ }
+
return TRUE;
+fail10:
+ Log("fail10");
+
+fail9:
+ Log("fail9");
+
+ free(Context->Question);
+
+fail8:
+ Log("fail8");
+
fail7:
Log("fail7");
return FALSE;
}
-
-
VOID WINAPI
MonitorMain(
_In_ DWORD argc,
done:
(VOID) RegDeleteTree(Context->RequestKey, NULL);
+ free(Context->Question);
free(Context->Text);
free(Context->Title);
CloseHandle(Context->RequestKey);
HKR,"Parameters","RequestKey",0x00000000,%RequestKey%
HKR,"Parameters","DialogTitle",0x00000000,%DialogTitle%
HKR,"Parameters","DialogText",0x00000000,%DialogText%
+HKR,"Parameters","DialogQuestion",0x00000000,%DialogQuestion%
[Monitor_EventLog]
AddReg=Monitor_EventLog_AddReg
MonitorDesc="Provides support for @PRODUCT_NAME@ PV drivers"
RequestKey="SYSTEM\CurrentControlSet\Services\xenbus_monitor\Request"
DialogTitle="@PRODUCT_NAME@"
-DialogText="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."
+DialogText="needs to restart the system to complete installation."
+DialogQuestion="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