Repository navigation
Expand file tree
/
Copy pathHashCheckInstall.c
More file actions
73 lines (64 loc) · 3.19 KB
/
Copy pathHashCheckInstall.c
File metadata and controls
73 lines (64 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* HashCheck uninstall registration
* Copyright (C) 2026 Mounir IDRASSI. All rights reserved.
* Please refer to license.txt for details about distribution and modification.
**/
#include "globals.h"
#include "HashCheckInstall.h"
#include "RegHelpers.h"
#include "libs/Wow64.h"
#include <strsafe.h>
static const TCHAR szUninstallKey[] =
TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\") UNINSTALL_KEY_STR_HashCheck;
static const TCHAR szLegacyUninstallKey[] =
TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\HashCheck Shell Extension");
BOOL WINAPI RegisterUninstallEntry( LPCTSTR lpszDllPath )
{
TCHAR szUninstall[MAX_PATH << 1];
TCHAR szQuietUninstall[MAX_PATH << 1];
HKEY hKey;
DWORD dwDisposition;
BOOL bSuccess;
if (FAILED(StringCchPrintf(szUninstall, countof(szUninstall),
TEXT("regsvr32.exe /u /i /n /s \"%s\""), lpszDllPath)) ||
FAILED(StringCchPrintf(szQuietUninstall, countof(szQuietUninstall),
TEXT("regsvr32.exe /u /i:\"NoRebootPrompt\" /n /s \"%s\""), lpszDllPath)))
return(FALSE);
// Use the calling DLL's registry view. On 64-bit Windows only the native
// DLL registers an uninstaller; the companion DLL uses NoUninstall.
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szUninstallKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, &dwDisposition) != ERROR_SUCCESS)
return(FALSE);
Wow64DisableRegReflection(hKey);
bSuccess =
RegSetSZ(hKey, TEXT("DisplayIcon"), lpszDllPath) &&
RegSetSZ(hKey, TEXT("DisplayName"), TEXT(HASHCHECK_NAME_STR)) &&
RegSetSZ(hKey, TEXT("DisplayVersion"), TEXT(HASHCHECK_VERSION_STR)) &&
RegSetSZ(hKey, TEXT("Publisher"), PUBLISHER_STR_HashCheck) &&
RegSetDW(hKey, TEXT("EstimatedSize"), 1073) &&
RegSetSZ(hKey, TEXT("HelpLink"), TEXT("https://github.com/idrassi/HashCheck/issues")) &&
RegSetDW(hKey, TEXT("NoModify"), 1) &&
RegSetDW(hKey, TEXT("NoRepair"), 1) &&
RegSetSZ(hKey, TEXT("UninstallString"), szUninstall) &&
RegSetSZ(hKey, TEXT("QuietUninstallString"), szQuietUninstall) &&
RegSetSZ(hKey, TEXT("URLInfoAbout"), TEXT("https://github.com/idrassi/HashCheck")) &&
RegSetSZ(hKey, TEXT("URLUpdateInfo"), TEXT("https://github.com/idrassi/HashCheck/releases/latest"));
RegCloseKey(hKey);
if (!bSuccess)
{
if (dwDisposition == REG_CREATED_NEW_KEY)
RegDelete(HKEY_LOCAL_MACHINE, szUninstallKey, NULL);
return(FALSE);
}
// Installation has already replaced the shared shell registration. Remove
// the superseded ARP identity only after its replacement has been written.
return(RegDelete(HKEY_LOCAL_MACHINE, szLegacyUninstallKey, NULL));
}
BOOL WINAPI UnregisterUninstallEntry( VOID )
{
// Also used by NoUninstall, so stale entries in the companion DLL's view
// are removed without touching the native DLL's entry.
BOOL bCurrentDeleted = RegDelete(HKEY_LOCAL_MACHINE, szUninstallKey, NULL);
BOOL bLegacyDeleted = RegDelete(HKEY_LOCAL_MACHINE, szLegacyUninstallKey, NULL);
return(bCurrentDeleted && bLegacyDeleted);
}