[UMPNPMGR] Implement registry functions for SuppressUI and SuppressNewHWUI handling. (#1683)

CORE-15897

Co-authored-by: Hermès Bélusca-Maïto <[email protected]>
This commit is contained in:
Bișoc George
2019-07-21 19:02:53 +02:00
co-authored by Hermès Bélusca-Maïto
parent e0c97c9eca
commit eede1b9b7a
3 changed files with 97 additions and 3 deletions
+10 -1
View File
@@ -340,6 +340,15 @@ cleanup:
}
FORCEINLINE
BOOL
IsUISuppressionAllowed(VOID)
{
/* Display the newdev.dll wizard UI only if it's allowed */
return (g_IsUISuppressed || GetSuppressNewUIValue());
}
/* Loop to install all queued devices installations */
DWORD
WINAPI
@@ -368,7 +377,7 @@ DeviceInstallThread(LPVOID lpParameter)
{
ResetEvent(hNoPendingInstalls);
Params = CONTAINING_RECORD(ListEntry, DeviceInstallParams, ListEntry);
InstallDevice(Params->DeviceIds, showWizard);
InstallDevice(Params->DeviceIds, showWizard && !IsUISuppressionAllowed());
HeapFree(GetProcessHeap(), 0, Params);
}
}
+7 -1
View File
@@ -39,7 +39,6 @@ typedef struct
WCHAR DeviceIds[1];
} DeviceInstallParams;
/* install.c */
extern HANDLE hUserToken;
@@ -52,6 +51,10 @@ extern HANDLE hDeviceInstallListNotEmpty;
BOOL
SetupIsActive(VOID);
FORCEINLINE
BOOL
IsUISuppressionAllowed(VOID);
DWORD
WINAPI
DeviceInstallThread(
@@ -70,6 +73,9 @@ RpcServerThread(
extern HKEY hEnumKey;
extern HKEY hClassKey;
extern BOOL g_IsUISuppressed;
BOOL
GetSuppressNewUIValue(VOID);
#endif /* _UMPNPMGR_PCH_ */
+80 -1
View File
@@ -43,7 +43,7 @@ static SERVICE_STATUS ServiceStatus;
HKEY hEnumKey = NULL;
HKEY hClassKey = NULL;
BOOL g_IsUISuppressed = FALSE;
/* FUNCTIONS *****************************************************************/
@@ -268,6 +268,77 @@ ServiceControlHandler(DWORD dwControl,
}
}
static DWORD
GetBooleanRegValue(
IN HKEY hKey,
IN PCWSTR lpSubKey,
IN PCWSTR lpValue,
OUT PBOOL pValue)
{
DWORD dwError, dwType, dwData;
DWORD cbData = sizeof(dwData);
HKEY hSubKey = NULL;
/* Default value */
*pValue = FALSE;
dwError = RegOpenKeyExW(hKey,
lpSubKey,
0,
KEY_READ,
&hSubKey);
if (dwError != ERROR_SUCCESS)
{
DPRINT("GetBooleanRegValue(): RegOpenKeyExW() has failed to open '%S' key! (Error: %lu)\n",
lpSubKey, dwError);
return dwError;
}
dwError = RegQueryValueExW(hSubKey,
lpValue,
0,
&dwType,
(PBYTE)&dwData,
&cbData);
if (dwError != ERROR_SUCCESS)
{
DPRINT("GetBooleanRegValue(): RegQueryValueExW() has failed to query '%S' value! (Error: %lu)\n",
lpValue, dwError);
goto Cleanup;
}
if (dwType != REG_DWORD)
{
DPRINT("GetBooleanRegValue(): The value is not of REG_DWORD type!\n");
goto Cleanup;
}
/* Return the value */
*pValue = (dwData == 1);
Cleanup:
RegCloseKey(hSubKey);
return dwError;
}
BOOL
GetSuppressNewUIValue(VOID)
{
BOOL bSuppressNewHWUI = FALSE;
/*
* Query the SuppressNewHWUI policy registry value. Don't cache it
* as we want to update our behaviour in consequence.
*/
GetBooleanRegValue(HKEY_LOCAL_MACHINE,
L"Software\\Policies\\Microsoft\\Windows\\DeviceInstall\\Settings",
L"SuppressNewHWUI",
&bSuppressNewHWUI);
if (bSuppressNewHWUI)
DPRINT("GetSuppressNewUIValue(): newdev.dll's wizard UI won't be shown!\n");
return bSuppressNewHWUI;
}
VOID WINAPI
ServiceMain(DWORD argc, LPTSTR *argv)
@@ -363,6 +434,14 @@ InitializePnPManager(VOID)
InitializeSListHead(&DeviceInstallListHead);
/* Query the SuppressUI registry value and cache it for our whole lifetime */
GetBooleanRegValue(HKEY_LOCAL_MACHINE,
L"System\\CurrentControlSet\\Services\\PlugPlay\\Parameters",
L"SuppressUI",
&g_IsUISuppressed);
if (g_IsUISuppressed)
DPRINT("UMPNPMGR: newdev.dll's wizard UI won't be shown!\n");
dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"System\\CurrentControlSet\\Enum",
0,