Bump to 1.11

This commit is contained in:
Vichingo455
2025-03-23 12:49:51 +01:00
parent 7ca9105b8d
commit 23ac8a27f0
65 changed files with 2470 additions and 3597 deletions

View File

@@ -2,15 +2,22 @@
#include <comdef.h>
#include "Utils.h"
typedef BOOL (WINAPI *_Wow64DisableWow64FsRedirection)(PVOID *OldValue);
typedef BOOL (WINAPI *_Wow64RevertWow64FsRedirection)(PVOID OldValue);
#ifndef PROCESS_PER_MONITOR_DPI_AWARE
typedef int PROCESS_DPI_AWARENESS;
#define PROCESS_PER_MONITOR_DPI_AWARE 2
#endif
#ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
typedef int DPI_AWARENESS_CONTEXT;
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((DPI_AWARENESS_CONTEXT)-4)
#endif
typedef BOOL (WINAPI *_GetProductInfo)(DWORD, DWORD, DWORD, DWORD, PDWORD);
// XP+
_Wow64DisableWow64FsRedirection $Wow64DisableWow64FsRedirection = (_Wow64DisableWow64FsRedirection)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "Wow64DisableWow64FsRedirection");
_Wow64RevertWow64FsRedirection $Wow64RevertWow64FsRedirection = (_Wow64RevertWow64FsRedirection)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "Wow64RevertWow64FsRedirection");
typedef BOOL (WINAPI *_SetProcessDpiAwarenessContext)(DPI_AWARENESS_CONTEXT);
typedef HRESULT (WINAPI *_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS);
typedef void (WINAPI *_SetProcessDPIAware)();
// Vista+
_GetProductInfo $GetProductInfo = (_GetProductInfo)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetProductInfo");
BOOL GetVistaProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion, DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType) {
@@ -22,18 +29,25 @@ BOOL GetVistaProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD d
}
}
BOOL DisableWow64FsRedirection(PVOID *OldValue) {
if ($Wow64DisableWow64FsRedirection) {
return $Wow64DisableWow64FsRedirection(OldValue);
} else {
return TRUE;
void BecomeDPIAware() {
// Make the process DPI-aware... hopefully
// Windows 10 1703+ per-monitor v2
_SetProcessDpiAwarenessContext $SetProcessDpiAwarenessContext = (_SetProcessDpiAwarenessContext)GetProcAddress(LoadLibrary(L"user32.dll"), "SetProcessDpiAwarenessContext");
if ($SetProcessDpiAwarenessContext) {
$SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
return;
}
}
BOOL RevertWow64FsRedirection(PVOID OldValue) {
if ($Wow64RevertWow64FsRedirection) {
return $Wow64RevertWow64FsRedirection(OldValue);
} else {
return TRUE;
// Windows 8.1 - 10 1607 per-monitor v1
_SetProcessDpiAwareness $SetProcessDpiAwareness = (_SetProcessDpiAwareness)GetProcAddress(LoadLibrary(L"shcore.dll"), "SetProcessDpiAwareness");
if ($SetProcessDpiAwareness) {
$SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
return;
}
// Windows Vista - 8
_SetProcessDPIAware $SetProcessDPIAware = (_SetProcessDPIAware)GetProcAddress(LoadLibrary(L"user32.dll"), "SetProcessDPIAware");
if ($SetProcessDPIAware) {
$SetProcessDPIAware();
}
}

View File

@@ -1,6 +1,4 @@
#pragma once
BOOL GetVistaProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion, DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType);
BOOL DisableWow64FsRedirection(PVOID *OldValue);
BOOL RevertWow64FsRedirection(PVOID OldValue);
void BecomeDPIAware();

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<applications xmlns="http://schemas.microsoft.com/windows/cpltasks/v1" xmlns:sh="http://schemas.microsoft.com/windows/tasks/v1">
<application id="{FFBE8D44-E9CF-4DD8-9FD6-976802C94D9C}">
<sh:task id="{9943E8C8-748D-47CE-AE10-9FA4A80ED28B}" needsElevation="true">
<sh:name>@&quot;%ProgramFiles%\Legacy Update\LegacyUpdate.dll&quot;,-3</sh:name>
<sh:keywords>legacy update;legacyupdate;update;windows;microsoft;driver;security;software;</sh:keywords>
<sh:command>%windir%\system32\rundll32.exe &quot;%ProgramFiles%\Legacy Update\LegacyUpdate.dll&quot;,LaunchUpdateSite</sh:command>
</sh:task>
<category id="5">
<sh:task idref="{9943E8C8-748D-47CE-AE10-9FA4A80ED28B}" />
</category>
<category id="10">
<sh:task idref="{9943E8C8-748D-47CE-AE10-9FA4A80ED28B}" />
</category>
</application>
</applications>

View File

@@ -1,6 +1,8 @@
// ElevationHelper.cpp : Implementation of CElevationHelper
#include "stdafx.h"
#include "Compat.h"
#include "ElevationHelper.h"
#include "HResult.h"
#include "Utils.h"
#include <strsafe.h>
@@ -8,18 +10,18 @@ const BSTR permittedProgIDs[] = {
L"Microsoft.Update.",
NULL
};
const int permittedProgIDsMax = 1;
BOOL ProgIDIsPermitted(PWSTR progID) {
if (progID == NULL) {
return FALSE;
}
for (int i = 0; i < permittedProgIDsMax; i++) {
for (int i = 0; permittedProgIDs[i] != NULL; i++) {
if (wcsncmp(progID, permittedProgIDs[i], wcslen(permittedProgIDs[i])) == 0) {
return TRUE;
}
}
return FALSE;
}
@@ -41,7 +43,11 @@ STDMETHODIMP CoCreateInstanceAsAdmin(HWND hwnd, __in REFCLSID rclsid, __in REFII
return CoGetObject(monikerName, &bindOpts, riid, ppv);
}
HRESULT CElevationHelper::CreateObject(BSTR progID, IDispatch **retval) {
CElevationHelper::CElevationHelper() {
BecomeDPIAware();
}
STDMETHODIMP CElevationHelper::CreateObject(BSTR progID, IDispatch **retval) {
if (progID == NULL) {
return E_INVALIDARG;
}
@@ -72,3 +78,7 @@ end:
}
return hr;
}
STDMETHODIMP CElevationHelper::Reboot(void) {
return ::Reboot();
}

View File

@@ -17,7 +17,7 @@ class ATL_NO_VTABLE CElevationHelper :
public IDispatchImpl<IElevationHelper, &IID_IElevationHelper, &LIBID_LegacyUpdateLib, /*wMajor =*/ 1, /*wMinor =*/ 0> {
public:
CElevationHelper() {}
CElevationHelper();
DECLARE_REGISTRY_RESOURCEID(IDR_ELEVATIONHELPER)
@@ -39,6 +39,7 @@ public:
void FinalRelease() {}
STDMETHODIMP CreateObject(BSTR progID, IDispatch **retval);
STDMETHODIMP Reboot(void);
};
OBJECT_ENTRY_AUTO(__uuidof(ElevationHelper), CElevationHelper)

View File

@@ -19,13 +19,12 @@ HKCR
val ThreadingModel = s 'Apartment'
}
val AppID = s '%APPID%'
val LocalizedString = s '@%MODULE%,-2'
val LocalizedString = s '@%MODULE%,-1'
TypeLib = s '{05D22F33-C7C3-4C90-BDD9-CEDC86EA8FBE}'
Version = s '1.0'
Elevation
{
val Enabled = d '1'
val IconReference = s '@%MODULE%,-201'
}
}
}

View File

@@ -1,174 +1,36 @@
#include "stdafx.h"
#include <comdef.h>
#include <ShellAPI.h>
#include <ShlObj.h>
#include <ExDisp.h>
#include <strsafe.h>
#include "Utils.h"
#include "LegacyUpdate_i.h"
#include "dllmain.h"
const LPCSTR UpdateSiteHostname = "legacyupdate.net";
const LPWSTR UpdateSiteURLHttp = L"http://legacyupdate.net/windowsupdate/v6/";
const LPWSTR UpdateSiteURLHttps = L"https://legacyupdate.net/windowsupdate/v6/";
const LPWSTR UpdateSiteFirstRunFlag = L"?firstrun=true";
static BOOL CanUseSSLConnection() {
// Get the Windows Update website URL set by Legacy Update setup
LPWSTR data;
DWORD size;
HRESULT hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate", L"URL", NULL, &data, &size);
if (!SUCCEEDED(hr)) {
goto end;
}
// Return based on the URL value
if (StrCmpW(data, UpdateSiteURLHttps) == 0) {
return TRUE;
} else if (StrCmpW(data, UpdateSiteURLHttp) == 0) {
return FALSE;
}
end:
// Fallback: Use SSL only on Vista and up
OSVERSIONINFOEX *versionInfo = GetVersionInfo();
return versionInfo->dwMajorVersion > 5;
}
#include "Exec.h"
#include "HResult.h"
#include "LegacyUpdate.h"
#include <shellapi.h>
// Function signature required by Rundll32.exe.
void CALLBACK LaunchUpdateSite(HWND hwnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) {
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
CComPtr<IWebBrowser2> browser;
CComVariant url;
CComVariant flags(0);
CComVariant nullVariant;
LPWSTR path;
if (!SUCCEEDED(hr)) {
goto end;
}
// If running on 2k/XP, make sure we're elevated. If not, show Run As prompt.
if (GetVersionInfo()->dwMajorVersion < 6 && !IsUserAnAdmin()) {
LPWSTR filename;
DWORD filenameSize;
GetOwnFileName(&filename, &filenameSize);
WCHAR args[MAX_PATH + 20];
StringCchPrintfW(args, filenameSize + 20, L"\"%ls\",LaunchUpdateSite", filename);
// Ignore C4311 and C4302, which is for typecasts. It is due to ShellExec and should be safe to bypass.
#pragma warning(disable: 4311 4302)
int execResult = (int)ShellExecute(NULL, L"runas", L"rundll32.exe", args, NULL, SW_SHOWDEFAULT);
#pragma warning(default: 4311 4302)
// Access denied happens when the user clicks No/Cancel.
if (execResult <= 32 && execResult != SE_ERR_ACCESSDENIED) {
hr = E_FAIL;
}
goto end;
}
// Spawn an IE window via the COM interface. This ensures the page opens in IE (ShellExecute uses
// default browser), and avoids hardcoding a path to iexplore.exe. Also conveniently allows testing
// on Windows 11 (iexplore.exe redirects to Edge, but COM still works). Same strategy as used by
// Wupdmgr.exe and Muweb.dll,LaunchMUSite.
hr = browser.CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER);
if (hr == REGDB_E_CLASSNOTREG) {
// Handle case where the user has uninstalled Internet Explorer using Programs and Features.
OSVERSIONINFOEX *versionInfo = GetVersionInfo();
// Windows 8+: Directly prompt to reinstall IE using Fondue.exe.
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
LPWSTR archSuffix = systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ? L"amd64" : L"x86";
WCHAR fondueArgs[256];
StringCchPrintfW(fondueArgs, 256, L"/enable-feature:Internet-Explorer-Optional-%ls", archSuffix);
#pragma warning(disable: 4311 4302)
int execResult = (int)ShellExecute(NULL, L"open", L"fondue.exe", fondueArgs, NULL, SW_SHOWDEFAULT);
#pragma warning(default: 4311 4302)
if (execResult <= 32) {
// Tell the user what they need to do, then open the Optional Features dialog.
WCHAR message[4096];
LoadString(g_hInstance, IDS_IENOTINSTALLED, message, ARRAYSIZE(message));
MessageBox(hwnd, message, L"Legacy Update", MB_OK | MB_ICONEXCLAMATION);
ShellExecute(NULL, L"open", L"OptionalFeatures.exe", NULL, NULL, SW_SHOWDEFAULT);
}
hr = S_OK;
goto end;
} else if (!SUCCEEDED(hr)) {
goto end;
}
// Can we connect with https? WinInet will throw an error if not.
LPWSTR siteURL = CanUseSSLConnection() ? UpdateSiteURLHttps : UpdateSiteURLHttp;
// Is this a first run launch? Append first run flag if so.
if (strcmp(lpszCmdLine, "firstrun") == 0) {
WCHAR newSiteURL[256];
StringCchPrintfW(newSiteURL, 256, L"%s%s", siteURL, UpdateSiteFirstRunFlag);
siteURL = newSiteURL;
}
url = siteURL;
hr = browser->Navigate2(&url, &flags, &nullVariant, &nullVariant, &nullVariant);
// This just calls LegacyUpdate.exe now for backwards compatibility.
hr = GetInstallPath(&path);
if (!SUCCEEDED(hr)) {
goto end;
}
HWND ieHwnd;
hr = browser->get_HWND((SHANDLE_PTR *)&ieHwnd);
if (!SUCCEEDED(hr)) {
goto end;
PathAppend(path, L"LegacyUpdate.exe");
DWORD code;
hr = Exec(L"open", path, NULL, NULL, nCmdShow, TRUE, &code);
if (SUCCEEDED(hr)) {
hr = HRESULT_FROM_WIN32(code);
}
// Are we on a small display? If so, resize and maximise the window.
HMONITOR monitor = MonitorFromWindow(ieHwnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFO);
if (GetMonitorInfo(monitor, &monitorInfo) > 0) {
LONG workWidth = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
LONG workHeight = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
LONG width, height;
browser->get_Width(&width);
browser->get_Height(&height);
if (width < 800) {
width = min(800, workWidth);
browser->put_Width(width);
}
if (height < 600) {
height = min(600, workHeight);
browser->put_Height(height);
}
LONG left, top;
browser->get_Left(&left);
browser->get_Top(&top);
if (left + width > workWidth) {
browser->put_Left(0);
}
if (top + height > workHeight) {
browser->put_Top(0);
}
if (workWidth <= 1152) {
ShowWindow(ieHwnd, SW_MAXIMIZE);
}
}
browser->put_Visible(TRUE);
// Focus the window, since it seems to not always get focus as it should.
SetForegroundWindow(ieHwnd);
end:
if (!SUCCEEDED(hr)) {
MessageBox(NULL, GetMessageForHresult(hr), L"Legacy Update", MB_OK | MB_ICONEXCLAMATION);
MessageBox(NULL, GetMessageForHresult(hr), L"Legacy Update", MB_OK | MB_ICONERROR);
}
browser = NULL;
CoUninitialize();
}

View File

@@ -1,8 +1,14 @@
; LegacyUpdate.def : Declares the module parameters.
EXPORTS
DllCanUnloadNow PRIVATE
DllGetClassObject PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
LaunchUpdateSite PRIVATE
; Registration
DllCanUnloadNow PRIVATE
DllGetClassObject PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
; Rundll32
LaunchUpdateSite PRIVATE
; Internal use
GetMessageForHresult

View File

@@ -8,8 +8,9 @@
#include <idispids.h>
import "oaidl.idl";
import "ocidl.idl";
import "wuapi.idl";
typedef enum {
typedef enum OSVersionField {
e_majorVer = 0,
e_minorVer = 1,
e_buildNumber = 2,
@@ -27,7 +28,7 @@ typedef enum {
e_maxOSVersionFieldValue = 13
} OSVersionField;
typedef enum {
typedef enum UserType {
e_nonAdmin = 0,
e_admin = 2,
e_elevated = 3
@@ -47,6 +48,7 @@ interface ILegacyUpdateCtrl : IDispatch {
[id(3)] HRESULT GetOSVersionInfo(OSVersionField osField, LONG systemMetric, [out, retval] VARIANT *retval);
[id(14)] HRESULT RequestElevation(void);
[id(4)] HRESULT CreateObject(BSTR progID, [out, retval] IDispatch **retval);
[id(15)] HRESULT SetBrowserHwnd(IUpdateInstaller *installer);
[id(5)] HRESULT GetUserType([out, retval] UserType *retval);
[id(8)] HRESULT RebootIfRequired(void);
[id(9)] HRESULT ViewWindowsUpdateLog(void);
@@ -83,6 +85,7 @@ interface IProgressBarControl : IDispatch
interface IElevationHelper : IDispatch
{
[id(1)] HRESULT CreateObject(BSTR progID, [out, retval] IDispatch **retval);
[id(2)] HRESULT Reboot(void);
};
[

View File

@@ -1,6 +1,7 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#include "Version.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
@@ -57,8 +58,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,9,0,0
PRODUCTVERSION 1,9,0,0
FILEVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH,VERSION_BUILD
PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH,VERSION_BUILD
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -75,12 +76,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Hashbang Productions"
VALUE "FileDescription", "Legacy Update"
VALUE "FileVersion", "1.9.0.0"
VALUE "FileVersion", VERSION_STRING
VALUE "InternalName", "LegacyUpdate.dll"
VALUE "LegalCopyright", "© Hashbang Productions. All rights reserved."
VALUE "OriginalFilename", "LegacyUpdate.dll"
VALUE "ProductName", "Legacy Update"
VALUE "ProductVersion", "1.9.0.0"
VALUE "ProductVersion", VERSION_STRING
END
END
BLOCK "VarFileInfo"
@@ -90,16 +91,6 @@ BEGIN
END
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "icon.ico"
/////////////////////////////////////////////////////////////////////////////
//
// REGISTRY
@@ -114,14 +105,6 @@ IDR_PROGRESSBARCONTROL REGISTRY "ProgressBarControl.rgs"
IDR_ELEVATIONHELPER REGISTRY "ElevationHelper.rgs"
/////////////////////////////////////////////////////////////////////////////
//
// XML
//
IDR_CPLTASKS XML "CplTasks.xml"
/////////////////////////////////////////////////////////////////////////////
//
// String Table
@@ -129,11 +112,7 @@ IDR_CPLTASKS XML "CplTasks.xml"
STRINGTABLE
BEGIN
IDS_LEGACYUPDATEOCX "Legacy Update Control"
IDS_LEGACYUPDATE "Legacy Update"
IDS_CHECKFORUPDATES "Check for updates"
IDS_CHECKFORUPDATES_ALT "Check for software and driver updates via Legacy Update."
IDS_IENOTINSTALLED "Internet Explorer is not installed. Use Optional Features in Control Panel to install it before using Legacy Update."
END
#endif // English (United States) resources
@@ -148,6 +127,8 @@ END
//
1 TYPELIB "LegacyUpdate.tlb"
#include "wuerror.rc"
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -38,26 +38,28 @@
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v90</PlatformToolset>
<UseOfAtl>Dynamic</UseOfAtl>
<UseOfAtl>Static</UseOfAtl>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v90</PlatformToolset>
<UseOfAtl>Dynamic</UseOfAtl>
<UseOfAtl>Static</UseOfAtl>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141_xp</PlatformToolset>
<XPDeprecationWarning>false</XPDeprecationWarning>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141_xp</PlatformToolset>
<XPDeprecationWarning>false</XPDeprecationWarning>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
@@ -66,7 +68,7 @@
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v90</PlatformToolset>
<UseOfAtl>Static</UseOfAtl>
<UseOfMfc>Static</UseOfMfc>
<UseOfMfc>false</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
@@ -74,8 +76,9 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141_xp</PlatformToolset>
<XPDeprecationWarning>false</XPDeprecationWarning>
<UseOfAtl>Static</UseOfAtl>
<UseOfMfc>Static</UseOfMfc>
<UseOfMfc>false</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -137,12 +140,16 @@
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;_MERGE_PROXYSTUB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<CompileAs />
<MinimalRebuild>false</MinimalRebuild>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>.\LegacyUpdate.def</ModuleDefinitionFile>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalOptions>/filealign:0x200 %(AdditionalOptions)</AdditionalOptions>
<RegisterOutput>false</RegisterOutput>
</Link>
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -167,7 +174,7 @@
</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>cmd /c start "" taskkill /im iexplore.exe</Command>
<Command>cmd /c start /min "" taskkill /im iexplore.exe</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">
@@ -178,12 +185,16 @@
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;_MERGE_PROXYSTUB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<CompileAs />
<MinimalRebuild>false</MinimalRebuild>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>.\LegacyUpdate.def</ModuleDefinitionFile>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalOptions>/filealign:0x200 %(AdditionalOptions)</AdditionalOptions>
<RegisterOutput>false</RegisterOutput>
</Link>
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -206,7 +217,7 @@
</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>cmd /c start "" taskkill /im iexplore.exe</Command>
<Command>cmd /c start /min "" taskkill /im iexplore.exe</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">
@@ -217,12 +228,15 @@
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;_MERGE_PROXYSTUB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<CompileAs />
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>.\LegacyUpdate.def</ModuleDefinitionFile>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalOptions>/filealign:0x200 %(AdditionalOptions)</AdditionalOptions>
<RegisterOutput>false</RegisterOutput>
</Link>
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -247,7 +261,7 @@
</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>cmd /c start "" taskkill /im iexplore.exe</Command>
<Command>cmd /c start /min "" taskkill /im iexplore.exe</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">
@@ -258,12 +272,15 @@
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;_MERGE_PROXYSTUB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<CompileAs />
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>.\LegacyUpdate.def</ModuleDefinitionFile>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalOptions>/filealign:0x200 %(AdditionalOptions)</AdditionalOptions>
<RegisterOutput>false</RegisterOutput>
</Link>
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -286,19 +303,23 @@
</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>cmd /c start "" taskkill /im iexplore.exe</Command>
<Command>cmd /c start /min "" taskkill /im iexplore.exe</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<Optimization>
</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<IntrinsicFunctions>
</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;_MERGE_PROXYSTUB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<CompileAs />
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -309,6 +330,7 @@
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalDependencies>
</AdditionalDependencies>
<AdditionalOptions>/filealign:0x200 %(AdditionalOptions)</AdditionalOptions>
</Link>
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -329,19 +351,23 @@
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<PreBuildEvent>
<Command>cmd /c start "" taskkill /im iexplore.exe</Command>
<Command>cmd /c start /min "" taskkill /im iexplore.exe</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<Optimization>
</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<IntrinsicFunctions>
</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;_MERGE_PROXYSTUB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<CompileAs />
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -352,6 +378,7 @@
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalDependencies>
</AdditionalDependencies>
<AdditionalOptions>/filealign:0x200 %(AdditionalOptions)</AdditionalOptions>
</Link>
<Midl>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -371,7 +398,6 @@
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="CplTasks.xml" />
<None Include="ElevationHelper.rgs" />
<None Include="icon.ico" />
<None Include="LegacyUpdate.def" />
@@ -381,10 +407,87 @@
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="ProgressBarControl.rgs" />
<CustomBuild Include="wuerror.mc">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<FileType>Document</FileType>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">mc %(FullPath) -r $(IntDir) -h $(IntDir)</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compiling Message Table</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)%(Identity).rc;$(IntDir)%(Identity).h;$(IntDir)MSG0409.bin</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">mc %(FullPath) -r $(IntDir) -h $(IntDir)</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compiling Message Table</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)%(Identity).rc;$(IntDir)%(Identity).h;$(IntDir)MSG0409.bin</Outputs>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
</DeploymentContent>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">mc %(FullPath) -r $(IntDir) -h $(IntDir)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|Win32'">mc %(FullPath) -r $(IntDir) -h $(IntDir)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">mc %(FullPath) -r $(IntDir) -h $(IntDir)</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">mc %(FullPath) -r $(IntDir) -h $(IntDir)</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">Compiling Message Table</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|Win32'">Compiling Message Table</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">Compiling Message Table</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">Compiling Message Table</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">$(IntDir)%(Identity).rc;$(IntDir)%(Identity).h;$(IntDir)MSG0409.bin</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|Win32'">$(IntDir)%(Identity).rc;$(IntDir)%(Identity).h;$(IntDir)MSG0409.bin</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">$(IntDir)%(Identity).rc;$(IntDir)%(Identity).h;$(IntDir)MSG0409.bin</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">$(IntDir)%(Identity).rc;$(IntDir)%(Identity).h;$(IntDir)MSG0409.bin</Outputs>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">false</ExcludedFromBuild>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\shared\VersionInfo.cpp" />
<ClCompile Include="..\shared\WMI.cpp" />
<ClCompile Include="..\shared\Exec.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="..\shared\LegacyUpdate.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="..\shared\Registry.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="..\shared\VersionInfo.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="..\shared\HResult.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="..\shared\WMI.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC17|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug-VC08|x64'">CompileAsCpp</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="ElevationHelper.cpp" />
<ClCompile Include="LaunchUpdateSite.cpp" />
<ClCompile Include="LegacyUpdateCtrl.cpp" />
@@ -461,10 +564,15 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\wuerror.h" />
<ClInclude Include="..\shared\Exec.h" />
<ClInclude Include="..\shared\LegacyUpdate.h" />
<ClInclude Include="..\shared\VersionInfo.h" />
<ClInclude Include="..\shared\WMI.h" />
<ClInclude Include="..\shared\HResult.h" />
<ClInclude Include="Compat.h" />
<ClInclude Include="ElevationHelper.h" />
<ClInclude Include="IUpdateInstaller4.h" />
<ClInclude Include="LaunchUpdateSite.h" />
<ClInclude Include="LegacyUpdateCtrl.h" />
<ClInclude Include="ProgressBarControl.h" />
@@ -490,4 +598,4 @@
<UserProperties RESOURCE_FILE="LegacyUpdate.rc" />
</VisualStudio>
</ProjectExtensions>
</Project>
</Project>

View File

@@ -34,9 +34,6 @@
<Filter>Resource Files</Filter>
</None>
<None Include="ProgressBarControl.html" />
<None Include="CplTasks.xml">
<Filter>Resource Files</Filter>
</None>
<None Include="ElevationHelper.rgs">
<Filter>Resource Files</Filter>
</None>
@@ -72,10 +69,22 @@
<ClCompile Include="ElevationHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\shared\VersionInfo.cpp">
<ClCompile Include="..\shared\WMI.c">
<Filter>Shared</Filter>
</ClCompile>
<ClCompile Include="..\shared\WMI.cpp">
<ClCompile Include="..\shared\Registry.c">
<Filter>Shared</Filter>
</ClCompile>
<ClCompile Include="..\shared\VersionInfo.c">
<Filter>Shared</Filter>
</ClCompile>
<ClCompile Include="..\shared\HResult.c">
<Filter>Shared</Filter>
</ClCompile>
<ClCompile Include="..\shared\Exec.c">
<Filter>Shared</Filter>
</ClCompile>
<ClCompile Include="..\shared\LegacyUpdate.c">
<Filter>Shared</Filter>
</ClCompile>
</ItemGroup>
@@ -122,6 +131,21 @@
<ClInclude Include="..\shared\VersionInfo.h">
<Filter>Shared</Filter>
</ClInclude>
<ClInclude Include="..\shared\HResult.h">
<Filter>Shared</Filter>
</ClInclude>
<ClInclude Include="..\include\wuerror.h">
<Filter>Shared</Filter>
</ClInclude>
<ClInclude Include="IUpdateInstaller4.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\shared\Exec.h">
<Filter>Shared</Filter>
</ClInclude>
<ClInclude Include="..\shared\LegacyUpdate.h">
<Filter>Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="LegacyUpdate.rc">
@@ -132,5 +156,13 @@
<Midl Include="LegacyUpdate.idl">
<Filter>Source Files</Filter>
</Midl>
<Midl Include="wuapi.idl">
<Filter>Source Files</Filter>
</Midl>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="wuerror.mc">
<Filter>Resource Files</Filter>
</CustomBuild>
</ItemGroup>
</Project>

View File

@@ -2,13 +2,20 @@
#include "stdafx.h"
#include "LegacyUpdateCtrl.h"
#include "Utils.h"
#include "Compat.h"
#include "ElevationHelper.h"
#include "Exec.h"
#include "HResult.h"
#include "LegacyUpdate.h"
#include "Registry.h"
#include "User.h"
#include "Utils.h"
#include "VersionInfo.h"
#include "WULog.h"
#include <atlbase.h>
#include <atlcom.h>
#include <ShellAPI.h>
#include <ShlObj.h>
#include <wuapi.h>
#include "IUpdateInstaller4.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -19,7 +26,6 @@ const BSTR permittedHosts[] = {
L"test.legacyupdate.net",
NULL
};
const int permittedHostsMax = 2;
// CLegacyUpdateCtrl message handlers
@@ -39,7 +45,7 @@ IHTMLDocument2 *CLegacyUpdateCtrl::GetHTMLDocument() {
}
CComPtr<IHTMLDocument2> document;
hr = container->QueryInterface(IID_IHTMLDocument2, (void**)&document);
hr = container->QueryInterface(IID_IHTMLDocument2, (void **)&document);
if (!SUCCEEDED(hr) || document == NULL) {
TRACE("GetDocument() failed: %ls\n", GetMessageForHresult(hr));
return NULL;
@@ -50,7 +56,7 @@ IHTMLDocument2 *CLegacyUpdateCtrl::GetHTMLDocument() {
HWND CLegacyUpdateCtrl::GetIEWindowHWND() {
CComPtr<IOleWindow> oleWindow;
HRESULT hr = QueryInterface(IID_IOleWindow, (void**)&oleWindow);
HRESULT hr = QueryInterface(IID_IOleWindow, (void **)&oleWindow);
if (!SUCCEEDED(hr) || !oleWindow) {
goto end;
}
@@ -94,7 +100,7 @@ BOOL CLegacyUpdateCtrl::IsPermitted(void) {
goto end;
}
for (int i = 0; i < permittedHostsMax; i++) {
for (int i = 0; permittedHosts[i] != NULL; i++) {
if (wcscmp(host, permittedHosts[i]) == 0) {
return TRUE;
}
@@ -107,22 +113,49 @@ end:
return FALSE;
}
STDMETHODIMP CLegacyUpdateCtrl::GetElevatedHelper(CComPtr<IElevationHelper> &retval) {
CComPtr<IElevationHelper> elevatedHelper = m_elevatedHelper ? m_elevatedHelper : m_nonElevatedHelper;
if (elevatedHelper == NULL) {
// Use the helper directly, without elevation. It's the responsibility of the caller to ensure it
// is already running as admin on 2k/XP, or that it has requested elevation on Vista+.
HRESULT hr = m_nonElevatedHelper.CoCreateInstance(CLSID_ElevationHelper, NULL, CLSCTX_INPROC_SERVER);
if (!SUCCEEDED(hr)) {
return hr;
}
elevatedHelper = m_nonElevatedHelper;
}
retval = elevatedHelper;
return S_OK;
}
#define DoIsPermittedCheck() \
if (!IsPermitted()) { \
return E_ACCESSDENIED; \
}
STDMETHODIMP CLegacyUpdateCtrl::SetClientSite(IOleClientSite *pClientSite) {
HRESULT hr = IOleObjectImpl::SetClientSite(pClientSite);
if (!SUCCEEDED(hr)) {
return hr;
}
DoIsPermittedCheck();
return S_OK;
}
STDMETHODIMP CLegacyUpdateCtrl::CheckControl(VARIANT_BOOL *retval) {
DoIsPermittedCheck();
// Just return true so the site can confirm the control is working.
*retval = TRUE;
*retval = VARIANT_TRUE;
return S_OK;
}
STDMETHODIMP CLegacyUpdateCtrl::MessageForHresult(LONG inHresult, BSTR *retval) {
DoIsPermittedCheck();
*retval = GetMessageForHresult(inHresult);
*retval = SysAllocString(GetMessageForHresult(inHresult));
return S_OK;
}
@@ -130,71 +163,78 @@ STDMETHODIMP CLegacyUpdateCtrl::GetOSVersionInfo(OSVersionField osField, LONG sy
DoIsPermittedCheck();
VariantInit(retval);
retval->vt = VT_I4;
OSVERSIONINFOEX *versionInfo = GetVersionInfo();
switch (osField) {
case e_majorVer:
retval->lVal = versionInfo->dwMajorVersion;
retval->vt = VT_UI4;
retval->ulVal = versionInfo->dwMajorVersion;
break;
case e_minorVer:
retval->lVal = versionInfo->dwMinorVersion;
retval->vt = VT_UI4;
retval->ulVal = versionInfo->dwMinorVersion;
break;
case e_buildNumber:
retval->lVal = versionInfo->dwBuildNumber;
retval->vt = VT_UI4;
retval->ulVal = versionInfo->dwBuildNumber;
break;
case e_platform:
retval->lVal = versionInfo->dwPlatformId;
retval->vt = VT_UI4;
retval->ulVal = versionInfo->dwPlatformId;
break;
case e_SPMajor:
retval->vt = VT_I4;
retval->lVal = versionInfo->wServicePackMajor;
break;
case e_SPMinor:
retval->vt = VT_I4;
retval->lVal = versionInfo->wServicePackMinor;
break;
case e_productSuite:
retval->vt = VT_I4;
retval->lVal = versionInfo->wSuiteMask;
break;
case e_productType:
retval->vt = VT_I4;
retval->lVal = versionInfo->wProductType;
break;
case e_systemMetric:
retval->vt = VT_I4;
retval->lVal = GetSystemMetrics(systemMetric);
break;
case e_SPVersionString: {
LPWSTR data;
DWORD size;
HRESULT hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"BuildLab", NULL, &data, &size);
if (SUCCEEDED(hr)) {
retval->vt = VT_BSTR;
retval->bstrVal = SysAllocStringLen(data, size - 1);
} else {
HRESULT hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"BuildLab", 0, &data, &size);
retval->vt = VT_BSTR;
retval->bstrVal = SUCCEEDED(hr)
? SysAllocStringLen(data, size - 1)
// BuildLab doesn't exist on Windows 2000.
retval->vt = VT_BSTR;
retval->bstrVal = SysAllocString(versionInfo->szCSDVersion);
: SysAllocString(versionInfo->szCSDVersion);
if (data) {
LocalFree(data);
}
break;
}
case e_controlVersionString: {
LPWSTR data;
DWORD size;
HRESULT hr = GetOwnVersion(&data, &size);
HRESULT hr = GetOwnVersion(&data);
if (!SUCCEEDED(hr)) {
return hr;
}
retval->vt = VT_BSTR;
retval->bstrVal = SysAllocStringLen(data, size - 1);
retval->bstrVal = SysAllocString(data);
break;
}
@@ -211,12 +251,10 @@ STDMETHODIMP CLegacyUpdateCtrl::GetOSVersionInfo(OSVersionField osField, LONG sy
if (!SUCCEEDED(hr)) {
LPWSTR data;
DWORD size;
hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"ProductName", NULL, &data, &size);
hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"ProductName", 0, &data, &size);
if (SUCCEEDED(hr)) {
retval->vt = VT_BSTR;
retval->bstrVal = SysAllocStringLen(data, size - 1);
} else {
VariantClear(retval);
}
}
break;
@@ -225,12 +263,11 @@ STDMETHODIMP CLegacyUpdateCtrl::GetOSVersionInfo(OSVersionField osField, LONG sy
case e_displayVersion: {
LPWSTR data;
DWORD size;
HRESULT hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"DisplayVersion", NULL, &data, &size);
HRESULT hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"DisplayVersion", 0, &data, &size);
if (SUCCEEDED(hr)) {
retval->vt = VT_BSTR;
retval->bstrVal = SysAllocStringLen(data, size - 1);
} else {
VariantClear(retval);
LocalFree(data);
}
break;
}
@@ -242,7 +279,7 @@ STDMETHODIMP CLegacyUpdateCtrl::GetOSVersionInfo(OSVersionField osField, LONG sy
STDMETHODIMP CLegacyUpdateCtrl::RequestElevation() {
DoIsPermittedCheck();
if (m_elevatedHelper != NULL || GetVersionInfo()->dwMajorVersion < 6) {
if (m_elevatedHelper != NULL || !AtLeastWinVista()) {
return S_OK;
}
@@ -269,15 +306,9 @@ STDMETHODIMP CLegacyUpdateCtrl::CreateObject(BSTR progID, IDispatch **retval) {
goto end;
}
elevatedHelper = m_elevatedHelper ? m_elevatedHelper : m_nonElevatedHelper;
if (elevatedHelper == NULL) {
// Use the helper directly, without elevation. It's the responsibility of the caller to ensure it
// is already running as admin on 2k/XP, or that it has requested elevation on Vista+.
m_nonElevatedHelper.CoCreateInstance(CLSID_ElevationHelper, NULL, CLSCTX_INPROC_SERVER);
if (!SUCCEEDED(hr)) {
goto end;
}
elevatedHelper = m_nonElevatedHelper;
hr = GetElevatedHelper(elevatedHelper);
if (!SUCCEEDED(hr)) {
goto end;
}
return elevatedHelper->CreateObject(progID, retval);
@@ -289,10 +320,27 @@ end:
return hr;
}
STDMETHODIMP CLegacyUpdateCtrl::SetBrowserHwnd(IUpdateInstaller *installer) {
DoIsPermittedCheck();
if (installer == NULL) {
return E_INVALIDARG;
}
CComPtr<IUpdateInstaller> updateInstaller = NULL;
HRESULT hr = installer->QueryInterface(IID_IUpdateInstaller, (void **)&updateInstaller);
if (!SUCCEEDED(hr)) {
return hr;
}
updateInstaller->put_ParentHwnd(GetIEWindowHWND());
return S_OK;
}
STDMETHODIMP CLegacyUpdateCtrl::GetUserType(UserType *retval) {
DoIsPermittedCheck();
if (IsUserAnAdmin()) {
if (IsUserAdmin()) {
// Entire process is elevated.
*retval = e_admin;
} else if (m_elevatedHelper != NULL) {
@@ -302,115 +350,147 @@ STDMETHODIMP CLegacyUpdateCtrl::GetUserType(UserType *retval) {
// The control has no admin rights (although it may not have requested them yet).
*retval = e_nonAdmin;
}
return S_OK;
}
STDMETHODIMP CLegacyUpdateCtrl::get_IsRebootRequired(VARIANT_BOOL *retval) {
DoIsPermittedCheck();
HKEY subkey;
HRESULT hr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired", 0, KEY_READ, &subkey);
*retval = subkey != NULL;
if (subkey != NULL) {
RegCloseKey(subkey);
// Ask WU itself whether a reboot is required
CComPtr<ISystemInformation> systemInfo;
if (SUCCEEDED(systemInfo.CoCreateInstance(CLSID_SystemInformation, NULL, CLSCTX_INPROC_SERVER))) {
if (SUCCEEDED(systemInfo->get_RebootRequired(retval)) && *retval == VARIANT_TRUE) {
return S_OK;
}
}
// Check reboot flag in registry
HKEY subkey;
HRESULT hr = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired", KEY_WOW64_64KEY, KEY_READ, &subkey));
if (SUCCEEDED(hr)) {
RegCloseKey(subkey);
*retval = VARIANT_TRUE;
return S_OK;
}
*retval = VARIANT_FALSE;
return S_OK;
}
STDMETHODIMP CLegacyUpdateCtrl::get_IsWindowsUpdateDisabled(VARIANT_BOOL *retval) {
DoIsPermittedCheck();
DWORD noWU;
HRESULT hr = GetRegistryDword(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", L"NoWindowsUpdate", NULL, &noWU);
if (SUCCEEDED(hr) && noWU == 1) {
*retval = TRUE;
// Future note: These are in HKCU on NT; HKLM on 9x.
// Remove links and access to Windows Update
DWORD value;
HRESULT hr = GetRegistryDword(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", L"NoWindowsUpdate", KEY_WOW64_64KEY, &value);
if (SUCCEEDED(hr) && value == 1) {
*retval = VARIANT_TRUE;
return S_OK;
}
DWORD disableWUAccess;
hr = GetRegistryDword(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\WindowsUpdate", L"DisableWindowsUpdateAccess", NULL, &disableWUAccess);
if (SUCCEEDED(hr) && disableWUAccess == 1) {
*retval = TRUE;
// Remove access to use all Windows Update features
hr = GetRegistryDword(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\WindowsUpdate", L"DisableWindowsUpdateAccess", KEY_WOW64_64KEY, &value);
if (SUCCEEDED(hr) && value == 1) {
*retval = VARIANT_TRUE;
return S_OK;
}
*retval = FALSE;
*retval = VARIANT_FALSE;
return S_OK;
}
STDMETHODIMP CLegacyUpdateCtrl::RebootIfRequired(void) {
DoIsPermittedCheck();
HRESULT hr = S_OK;
VARIANT_BOOL isRebootRequired;
if (SUCCEEDED(get_IsRebootRequired(&isRebootRequired)) && isRebootRequired) {
Reboot();
if (SUCCEEDED(get_IsRebootRequired(&isRebootRequired)) && isRebootRequired == VARIANT_TRUE) {
// Calling Commit() is recommended on Windows 10, to ensure feature updates are properly prepared
// prior to the reboot. If IUpdateInstaller4 doesn't exist, we can skip this.
CComPtr<IUpdateInstaller4> installer;
hr = installer.CoCreateInstance(CLSID_UpdateInstaller, NULL, CLSCTX_INPROC_SERVER);
if (SUCCEEDED(hr) && hr != REGDB_E_CLASSNOTREG) {
hr = installer->Commit(0);
if (!SUCCEEDED(hr)) {
return hr;
}
}
CComPtr<IElevationHelper> elevatedHelper;
hr = GetElevatedHelper(elevatedHelper);
if (!SUCCEEDED(hr)) {
return hr;
}
hr = elevatedHelper->Reboot();
}
return S_OK;
return hr;
}
static HRESULT StartLauncher(LPWSTR params, BOOL wait) {
LPWSTR path;
HRESULT hr = GetInstallPath(&path);
if (!SUCCEEDED(hr)) {
return hr;
}
PathAppend(path, L"LegacyUpdate.exe");
DWORD code;
hr = Exec(L"open", path, params, NULL, SW_SHOW, wait, &code);
if (SUCCEEDED(hr)) {
hr = HRESULT_FROM_WIN32(code);
}
return hr;
}
STDMETHODIMP CLegacyUpdateCtrl::ViewWindowsUpdateLog(void) {
DoIsPermittedCheck();
WCHAR windir[MAX_PATH];
HRESULT hr = SHGetFolderPath(0, CSIDL_WINDOWS, NULL, 0, windir);
HRESULT hr = StartLauncher(L"/log", FALSE);
if (!SUCCEEDED(hr)) {
TRACE(L"SHGetFolderPath() failed: %ls\n", GetMessageForHresult(hr));
return hr;
// Try directly
hr = ::ViewWindowsUpdateLog(SW_SHOWDEFAULT);
}
// Try Windows Server 2003 Resource Kit (or MSYS/Cygwin/etc) tail.exe, falling back to directly
// opening the file (most likely in Notepad).
// Ignore C4311 and C4302, which is for typecasts. It is due to ShellExec and should be safe to bypass.
#pragma warning(disable: 4311 4302)
if ((int)ShellExecute(NULL, L"open", L"tail.exe", L"-f WindowsUpdate.log", windir, SW_SHOWDEFAULT) > 32) {
return S_OK;
}
ShellExecute(NULL, L"open", L"WindowsUpdate.log", NULL, windir, SW_SHOWDEFAULT);
#pragma warning(default: 4311 4302)
return S_OK;
return hr;
}
STDMETHODIMP CLegacyUpdateCtrl::OpenWindowsUpdateSettings(void) {
DoIsPermittedCheck();
// Some issues arise from the working directory being SysWOW64 rather than System32. Notably,
// Windows Vista - 8.1 don't have wuauclt.exe in SysWOW64. Disable WOW64 redirection temporarily
// to work around this.
PVOID oldValue;
BOOL isRedirected = DisableWow64FsRedirection(&oldValue);
WCHAR systemDir[MAX_PATH];
HRESULT hr = SHGetFolderPath(0, CSIDL_SYSTEM, NULL, 0, systemDir);
HRESULT hr = StartLauncher(L"/options", FALSE);
if (!SUCCEEDED(hr)) {
TRACE(L"SHGetFolderPath() failed: %ls\n", GetMessageForHresult(hr));
return hr;
TRACE(L"OpenWindowsUpdateSettings() failed, falling back: %ls\n", GetMessageForHresult(hr));
// Might happen if the site isn't trusted, and the user rejected the IE medium integrity prompt.
// Use the basic Automatic Updates dialog directly from COM.
CComPtr<IAutomaticUpdates> automaticUpdates;
hr = automaticUpdates.CoCreateInstance(CLSID_AutomaticUpdates, NULL, CLSCTX_INPROC_SERVER);
if (SUCCEEDED(hr)) {
hr = automaticUpdates->ShowSettingsDialog();
}
if (!SUCCEEDED(hr)) {
TRACE(L"OpenWindowsUpdateSettings() failed: %ls\n", GetMessageForHresult(hr));
}
}
DWORD majorVersion = GetVersionInfo()->dwMajorVersion;
if (majorVersion >= 10) {
// Windows 10+: Open Settings app
ShellExecute(NULL, NULL, L"ms-settings:windowsupdate-options", NULL, systemDir, SW_SHOWDEFAULT);
} else if (majorVersion >= 6) {
// Windows Vista, 7, 8: Open Windows Update control panel
ShellExecute(NULL, NULL, L"wuauclt.exe", L"/ShowOptions", systemDir, SW_SHOWDEFAULT);
} else {
// Windows 2000, XP: Open Automatic Updates control panel
ShellExecute(NULL, NULL, L"wuaucpl.cpl", NULL, systemDir, SW_SHOWDEFAULT);
}
// Revert WOW64 redirection if we changed it.
if (isRedirected) {
RevertWow64FsRedirection(oldValue);
}
return S_OK;
return hr;
}
STDMETHODIMP CLegacyUpdateCtrl::get_IsUsingWsusServer(VARIANT_BOOL *retval) {
DoIsPermittedCheck();
DWORD useWUServer;
HRESULT hr = GetRegistryDword(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU", L"UseWUServer", NULL, &useWUServer);
*retval = SUCCEEDED(hr) && useWUServer == 1;
HRESULT hr = GetRegistryDword(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU", L"UseWUServer", 0, &useWUServer);
*retval = SUCCEEDED(hr) && useWUServer == 1 ? VARIANT_TRUE : VARIANT_FALSE;
return S_OK;
}
@@ -419,8 +499,11 @@ STDMETHODIMP CLegacyUpdateCtrl::get_WsusServerUrl(BSTR *retval) {
LPWSTR data;
DWORD size;
HRESULT hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate", L"WUServer", NULL, &data, &size);
HRESULT hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate", L"WUServer", 0, &data, &size);
*retval = SUCCEEDED(hr) ? SysAllocStringLen(data, size - 1) : NULL;
if (data) {
LocalFree(data);
}
return S_OK;
}
@@ -429,7 +512,10 @@ STDMETHODIMP CLegacyUpdateCtrl::get_WsusStatusServerUrl(BSTR *retval) {
LPWSTR data;
DWORD size;
HRESULT hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate", L"WUStatusServer", NULL, &data, &size);
HRESULT hr = GetRegistryString(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate", L"WUStatusServer", 0, &data, &size);
*retval = SUCCEEDED(hr) ? SysAllocStringLen(data, size - 1) : NULL;
if (data) {
LocalFree(data);
}
return S_OK;
}

View File

@@ -6,6 +6,7 @@
#include <atlctl.h>
#include <MsHTML.h>
#include <wuapi.h>
#include "resource.h"
#include "LegacyUpdate_i.h"
@@ -93,13 +94,17 @@ private:
IHTMLDocument2 *GetHTMLDocument();
HWND GetIEWindowHWND();
BOOL IsPermitted();
STDMETHODIMP GetElevatedHelper(CComPtr<IElevationHelper> &retval);
public:
STDMETHODIMP SetClientSite(IOleClientSite *pClientSite);
STDMETHODIMP CheckControl(VARIANT_BOOL *retval);
STDMETHODIMP MessageForHresult(LONG inHresult, BSTR *retval);
STDMETHODIMP GetOSVersionInfo(OSVersionField osField, LONG systemMetric, VARIANT *retval);
STDMETHODIMP RequestElevation();
STDMETHODIMP CreateObject(BSTR progID, IDispatch **retval);
STDMETHODIMP SetBrowserHwnd(IUpdateInstaller *installer);
STDMETHODIMP GetUserType(UserType *retval);
STDMETHODIMP get_IsRebootRequired(VARIANT_BOOL *retval);
STDMETHODIMP get_IsWindowsUpdateDisabled(VARIANT_BOOL *retval);

View File

@@ -1,9 +1,31 @@
override DEBUG := $(or $(DEBUG),1)
MSBUILDCONFIG32 = $(if $(filter 1,$(DEBUG)),Debug-VC08,Release)
MSBUILDCONFIG64 = $(if $(filter 1,$(DEBUG)),Debug-VC17,Release)
MSBUILDFLAGS = /v:minimal /m
ifeq ($(CI),1)
ifeq ($(DEBUG),1)
MSBUILDCONFIG32 = Debug-VC17
endif
MSBUILDFLAGS += /p:PlatformToolset=v141_xp
endif
MSBUILDFLAGS32 = $(MSBUILDFLAGS) /p:Configuration=$(MSBUILDCONFIG32) /p:Platform=Win32
MSBUILDFLAGS64 = $(MSBUILDFLAGS) /p:Configuration=$(MSBUILDCONFIG64) /p:Platform=x64
VSPATH ?= $(shell wslpath "$(shell '/mnt/c/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe' -latest -property installationPath)")
PATH := $(VSPATH)/MSBuild/Current/Bin:$(PATH)
MSBUILD = msbuild.exe
all:
cmd.exe /c build.cmd $(MSBUILDFLAGS)
@# Workaround for "dlldatax.obj: LNK2001: unresolved external symbol _LegacyUpdate_ProxyFileInfo"
rm -f LegacyUpdate_p.c
cd ..; $(MSBUILD) $(MSBUILDFLAGS32) LegacyUpdate.sln
rm -f LegacyUpdate_p.c
cd ..; $(MSBUILD) $(MSBUILDFLAGS64) LegacyUpdate.sln
ifeq ($(SIGN),1)
../build/sign.sh \
@@ -12,6 +34,10 @@ ifeq ($(SIGN),1)
endif
clean:
@# Not needed, build.cmd cleans before it builds
rm -rf \
Debug-VC08 Debug-VC17 Release x64 \
LegacyUpdate_i.c LegacyUpdate_i.h LegacyUpdate_p.c LegacyUpdateidl.h
cd ..; $(MSBUILD) $(MSBUILDFLAGS32) LegacyUpdate.sln /t:Clean
cd ..; $(MSBUILD) $(MSBUILDFLAGS64) LegacyUpdate.sln /t:Clean
.PHONY: all clean

View File

@@ -2,20 +2,14 @@
// Microsoft Visual C++ generated include file.
// Used by LegacyUpdate.rc
//
#define IDS_LEGACYUPDATEOCX 1
#define IDS_LEGACYUPDATE 2
#define IDS_CHECKFORUPDATES 3
#define IDS_CHECKFORUPDATES_ALT 4
#define IDS_IENOTINSTALLED 5
#define IDS_LEGACYUPDATE 1
#define IDR_LEGACYUPDATEOCX 101
#define IDR_LEGACYUPDATECTRL 102
#define IDR_PROGRESSBARCONTROL 103
#define IDR_ELEVATIONHELPER 104
#define IDI_ICON1 201
#define IDR_CPLTASKS 202
// Next default values for new objects
//
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 204

View File

@@ -1,176 +1,166 @@
#include "stdafx.h"
#include <comdef.h>
#include <atlstr.h>
#include <shlwapi.h>
#include "HResult.h"
#include "WMI.h"
#include "VersionInfo.h"
#pragma comment(lib, "version.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "shlwapi.lib")
#pragma comment(lib, "version.lib")
// Defined as being Vista+, older versions ignore the flag.
#ifndef EWX_RESTARTAPPS
#define EWX_RESTARTAPPS 0x00000040
#endif
extern "C" IMAGE_DOS_HEADER __ImageBase;
#define OwnModule ((HMODULE)&__ImageBase)
typedef DWORD (WINAPI *_InitiateShutdownW)(LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwGracePeriod, DWORD dwShutdownFlags, DWORD dwReason);
static BOOL _loadedProductName = FALSE;
static CComVariant _productName;
static BOOL _loadedOwnVersion = FALSE;
static LPWSTR _version;
static UINT _versionSize;
typedef struct {
DWORD version;
DWORD osFlag;
LPWSTR library;
UINT stringIDs[3];
} WinNT5Variant;
void GetOwnFileName(LPWSTR *filename, LPDWORD size) {
*filename = (LPWSTR)malloc(MAX_PATH);
*size = GetModuleFileName(OwnModule, *filename, MAX_PATH);
}
static const WinNT5Variant nt5Variants[] = {
// XP
{0x0501, OS_TABLETPC, L"winbrand.dll", { 180, 2000}},
{0x0501, OS_MEDIACENTER, L"winbrand.dll", { 180, 2001}},
{0x0501, OS_STARTER, L"winbrand.dll", { 180, 2002}},
{0x0501, OS_EMBPOS, L"winbrand.dll", { 180, 2003}},
{0x0501, OS_WINFLP, L"winbrand.dll", { 180, 2004}},
{0x0501, OS_EMBSTD2009, L"winbrand.dll", { 180, 2005}},
{0x0501, OS_EMBPOS2009, L"winbrand.dll", { 180, 2006}},
// Check for XP Embedded last as WES2009 also identifies as OS_EMBEDDED.
{0x0501, OS_EMBEDDED, L"sysdm.cpl", { 180, 189}},
HRESULT GetOwnVersion(LPWSTR *version, LPDWORD size) {
if (!_loadedOwnVersion) {
LPWSTR filename;
DWORD filenameSize;
GetOwnFileName(&filename, &filenameSize);
// Server 2003
{0x0502, OS_APPLIANCE, L"winbrand.dll", { 181, 2002}},
{0x0502, OS_STORAGESERVER, L"wssbrand.dll", {1101, 1102}},
{0x0502, OS_COMPUTECLUSTER, L"hpcbrand.dll", {1101, 1102, 1103}},
{0x0502, OS_HOMESERVER, L"whsbrand.dll", {1101, 1102}},
};
DWORD verHandle;
DWORD verInfoSize = GetFileVersionInfoSize(filename, &verHandle);
if (verInfoSize == 0) {
return AtlHresultFromLastError();
}
HRESULT GetOSProductName(LPVARIANT productName) {
if (!_loadedProductName) {
_loadedProductName = TRUE;
VariantInit(&_productName);
LPVOID verInfo = new BYTE[verInfoSize];
if (!GetFileVersionInfo(filename, verHandle, verInfoSize, verInfo)) {
return AtlHresultFromLastError();
}
if (!VerQueryValue(verInfo, L"\\StringFileInfo\\040904B0\\ProductVersion", (LPVOID *)&_version, &_versionSize)) {
return AtlHresultFromLastError();
}
}
*version = _version;
*size = _versionSize;
return _version == NULL ? E_FAIL : NOERROR;
}
HRESULT GetRegistryString(HKEY key, LPCWSTR subkeyPath, LPCWSTR valueName, LPDWORD type, LPWSTR *data, LPDWORD size) {
HKEY subkey;
HRESULT hr = HRESULT_FROM_WIN32(RegOpenKeyEx(key, subkeyPath, 0, KEY_READ, &subkey));
if (!SUCCEEDED(hr)) {
goto end;
}
if (data != NULL && size != NULL) {
DWORD length = 512 * sizeof(WCHAR);
LPWSTR buffer = (LPWSTR)malloc(length);
LSTATUS status;
do {
status = RegQueryValueEx(subkey, valueName, NULL, type, (BYTE *)buffer, &length);
if (status == ERROR_MORE_DATA) {
length += 256 * sizeof(WCHAR);
buffer = (LPWSTR)realloc(buffer, length);
} else if (status != ERROR_SUCCESS) {
hr = HRESULT_FROM_WIN32(status);
goto end;
// Handle the absolute disaster of Windows XP/Server 2003 edition branding
WORD winver = GetWinVer();
if (HIBYTE(winver) == 5) {
WinNT5Variant variant = {};
for (DWORD i = 0; i < ARRAYSIZE(nt5Variants); i++) {
if (winver == nt5Variants[i].version && IsOS(nt5Variants[i].osFlag)) {
variant = nt5Variants[i];
break;
}
}
} while (status == ERROR_MORE_DATA);
*data = buffer;
*size = length / sizeof(WCHAR);
}
if (variant.version) {
HMODULE brandDll = LoadLibraryEx(variant.library, NULL, LOAD_LIBRARY_AS_DATAFILE);
if (brandDll) {
WCHAR brandStr[1024];
ZeroMemory(brandStr, ARRAYSIZE(brandStr));
end:
if (subkey != NULL) {
RegCloseKey(subkey);
}
if (!SUCCEEDED(hr)) {
if (data != NULL) {
*data = NULL;
DWORD j = 0;
while (variant.stringIDs[j] != 0) {
UINT id = variant.stringIDs[j];
WCHAR str[340];
if (id == 180 || id == 181) {
// Get "Microsoft Windows XP" or "Microsoft Windows Server 2003" string
HMODULE sysdm = LoadLibraryEx(L"sysdm.cpl", NULL, LOAD_LIBRARY_AS_DATAFILE);
if (sysdm) {
LoadString(sysdm, id, str, ARRAYSIZE(str));
FreeLibrary(sysdm);
}
} else {
LoadString(brandDll, id, str, ARRAYSIZE(str));
}
if (j > 0) {
wcscat(brandStr, L" ");
}
wcscat(brandStr, str);
j++;
}
_productName.vt = VT_BSTR;
_productName.bstrVal = SysAllocString(brandStr);
FreeLibrary(brandDll);
}
}
}
if (size != NULL) {
*size = 0;
}
}
return hr;
}
HRESULT GetRegistryDword(HKEY key, LPCWSTR subkeyPath, LPCWSTR valueName, LPDWORD type, LPDWORD data) {
HKEY subkey;
HRESULT hr = HRESULT_FROM_WIN32(RegOpenKeyEx(key, subkeyPath, 0, KEY_READ, &subkey));
if (!SUCCEEDED(hr)) {
goto end;
}
if (data != NULL) {
DWORD length = sizeof(DWORD);
hr = HRESULT_FROM_WIN32(RegQueryValueEx(subkey, valueName, NULL, type, (LPBYTE)data, &length));
if (!SUCCEEDED(hr)) {
goto end;
if (_productName.vt == VT_EMPTY) {
// Get from WMI
HRESULT hr = QueryWMIProperty(L"SELECT Caption FROM Win32_OperatingSystem", L"Caption", &_productName);
if (!SUCCEEDED(hr)) {
return hr;
}
}
}
end:
if (subkey != NULL) {
RegCloseKey(subkey);
}
return hr;
}
LPWSTR GetMessageForHresult(HRESULT hr) {
_com_error *error = new _com_error(hr);
CString message = error->ErrorMessage();
BSTR outMessage = message.AllocSysString();
return outMessage;
}
HRESULT GetOSProductName(VARIANT *pProductName) {
if (_loadedProductName) {
VariantCopy(pProductName, &_productName);
return S_OK;
}
VariantInit(&_productName);
_loadedProductName = true;
return QueryWMIProperty(L"SELECT Caption FROM Win32_OperatingSystem", L"Caption", &_productName);
VariantCopy(productName, &_productName);
return S_OK;
}
HRESULT Reboot() {
HRESULT hr = E_FAIL;
// Make sure we have permission to shut down.
// Make sure we have permission to shut down
HANDLE token;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) {
LUID shutdownLuid;
if (LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &shutdownLuid) != 0) {
// Ask the system nicely to give us shutdown privilege.
TOKEN_PRIVILEGES privileges;
privileges.PrivilegeCount = 1;
privileges.Privileges[0].Luid = shutdownLuid;
privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(token, FALSE, &privileges, 0, NULL, NULL)) {
hr = AtlHresultFromLastError();
TRACE("AdjustTokenPrivileges() failed: %ls\n", GetMessageForHresult(hr));
}
}
} else {
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) {
hr = AtlHresultFromLastError();
TRACE("OpenProcessToken() failed: %ls\n", GetMessageForHresult(hr));
goto end;
}
// Reboot with reason "Operating System: Security fix (Unplanned)"
if (!InitiateSystemShutdownEx(NULL, NULL, 0, FALSE, TRUE, SHTDN_REASON_MAJOR_OPERATINGSYSTEM | SHTDN_REASON_MINOR_SECURITYFIX)) {
LUID shutdownLuid;
if (!LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &shutdownLuid)) {
hr = AtlHresultFromLastError();
TRACE("InitiateSystemShutdownExW() failed: %ls\n", GetMessageForHresult(hr));
TRACE("LookupPrivilegeValue() failed: %ls\n", GetMessageForHresult(hr));
goto end;
}
// Try ExitWindowsEx instead
// Win2k: Use ExitWindowsEx, which is only guaranteed to work for the current logged in user
if (!ExitWindowsEx(EWX_REBOOT | EWX_RESTARTAPPS | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OPERATINGSYSTEM | SHTDN_REASON_MINOR_SECURITYFIX)) {
// Ask the system nicely to give us shutdown privilege
TOKEN_PRIVILEGES privileges;
privileges.PrivilegeCount = 1;
privileges.Privileges[0].Luid = shutdownLuid;
privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(token, FALSE, &privileges, 0, NULL, NULL)) {
hr = AtlHresultFromLastError();
TRACE("AdjustTokenPrivileges() failed: %ls\n", GetMessageForHresult(hr));
goto end;
}
// Reboot with reason "Operating System: Security fix (Unplanned)", ensuring to install updates.
// Try InitiateShutdown first (Vista+)
_InitiateShutdownW $InitiateShutdownW = (_InitiateShutdownW)GetProcAddress(GetModuleHandle(L"advapi32.dll"), "InitiateShutdownW");
if ($InitiateShutdownW) {
hr = HRESULT_FROM_WIN32($InitiateShutdownW(NULL, NULL, 0, SHUTDOWN_RESTART | SHUTDOWN_INSTALL_UPDATES, SHTDN_REASON_MAJOR_OPERATINGSYSTEM | SHTDN_REASON_MINOR_SECURITYFIX));
}
// Try InitiateSystemShutdownEx (2k/XP)
if (!SUCCEEDED(hr)) {
TRACE("InitiateShutdown() failed: %ls\n", GetMessageForHresult(hr));
if (InitiateSystemShutdownEx(NULL, NULL, 0, FALSE, TRUE, SHTDN_REASON_MAJOR_OPERATINGSYSTEM | SHTDN_REASON_MINOR_SECURITYFIX) == 0) {
hr = AtlHresultFromLastError();
TRACE("ExitWindowsEx() failed: %ls\n", GetMessageForHresult(hr));
TRACE("InitiateSystemShutdownExW() failed: %ls\n", GetMessageForHresult(hr));
}
} else {
hr = S_OK;
}
// Last-ditch attempt ExitWindowsEx (only guaranteed to work for the current logged in user)
if (!ExitWindowsEx(EWX_REBOOT | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OPERATINGSYSTEM | SHTDN_REASON_MINOR_SECURITYFIX)) {
hr = AtlHresultFromLastError();
TRACE("ExitWindowsEx() failed: %ls\n", GetMessageForHresult(hr));
}
end:
if (token) {
CloseHandle(token);
}
return hr;

View File

@@ -1,15 +1,5 @@
#pragma once
OSVERSIONINFOEX *GetVersionInfo();
void GetOwnFileName(LPWSTR *filename, LPDWORD size);
HRESULT GetOwnVersion(LPWSTR *version, LPDWORD size);
HRESULT GetRegistryString(HKEY key, LPCWSTR subkeyPath, LPCWSTR valueName, LPDWORD type, LPWSTR *data, LPDWORD size);
HRESULT GetRegistryDword(HKEY key, LPCWSTR subkeyPath, LPCWSTR valueName, LPDWORD type, LPDWORD data);
LPWSTR GetMessageForHresult(HRESULT hresult);
HRESULT GetOSProductName(VARIANT* pProductName);
HRESULT GetOSProductName(LPVARIANT productName);
HRESULT Reboot();

View File

@@ -4,7 +4,7 @@
#define REGISTER_PROXY_DLL //DllRegisterServer, etc.
#define _WIN32_WINNT 0x0500 //for WinNT 4.0 or Win95 with DCOM
#define _WIN32_WINNT _WIN32_WINNT_WIN2K //for WinNT 4.0 or Win95 with DCOM
#define USE_STUBLESS_PROXY //defined only with MIDL switch /Oicf
#pragma comment(lib, "rpcns4.lib")

View File

@@ -1,10 +1,14 @@
// dllmain.cpp : Implementation of DLL Exports.
#include "stdafx.h"
#include "resource.h"
#include "LegacyUpdate_i.h"
#include "dllmain.h"
#include <strsafe.h>
#include "dlldatax.h"
#include "Registry.h"
#include "LegacyUpdate.h"
CLegacyUpdateModule _AtlModule;
HINSTANCE g_hInstance;
@@ -17,13 +21,13 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpRes
#endif
switch (dwReason) {
case DLL_PROCESS_ATTACH:
g_hInstance = hInstance;
break;
case DLL_PROCESS_ATTACH:
g_hInstance = hInstance;
break;
case DLL_PROCESS_DETACH:
g_hInstance = NULL;
break;
case DLL_PROCESS_DETACH:
g_hInstance = NULL;
break;
}
return _AtlModule.DllMain(dwReason, lpReserved);
@@ -57,10 +61,42 @@ STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) {
STDAPI DllRegisterServer(void) {
// registers object, typelib and all interfaces in typelib
HRESULT hr = _AtlModule.DllRegisterServer();
#ifdef _MERGE_PROXYSTUB
if (FAILED(hr)) {
if (!SUCCEEDED(hr)) {
return hr;
}
// Fix the icon path
HKEY subkey;
hr = HRESULT_FROM_WIN32(RegOpenKeyEx(HKEY_CLASSES_ROOT, L"CLSID\\{84F517AD-6438-478F-BEA8-F0B808DC257F}\\Elevation", 0, KEY_WRITE, &subkey));
if (!SUCCEEDED(hr)) {
return hr;
}
LPWSTR installPath;
hr = GetInstallPath(&installPath);
if (!SUCCEEDED(hr)) {
return hr;
}
WCHAR iconRef[512];
hr = StringCchPrintf((LPWSTR)&iconRef, ARRAYSIZE(iconRef), L"@%ls\\LegacyUpdate.exe,-100", installPath);
LocalFree(installPath);
if (!SUCCEEDED(hr)) {
return hr;
}
hr = HRESULT_FROM_WIN32(RegSetValueEx(subkey, L"IconReference", 0, REG_SZ, (LPBYTE)iconRef, (DWORD)(lstrlen(iconRef) + 1) * sizeof(TCHAR)));
if (!SUCCEEDED(hr)) {
return hr;
}
hr = RegCloseKey(subkey);
#ifdef _MERGE_PROXYSTUB
if (!SUCCEEDED(hr)) {
return hr;
}
hr = PrxDllRegisterServer();
#endif
return hr;

View File

@@ -2,10 +2,10 @@
#if _MSC_VER > 1599
// VC17: Windows XP
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define WINVER _WIN32_WINNT_WINXP
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#else
// VC08: Windows 2000 RTM
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
#define WINVER _WIN32_WINNT_WIN2K
#define _WIN32_WINNT _WIN32_WINNT_WIN2K
#endif