-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvcredist.cpp
More file actions
90 lines (75 loc) · 2.24 KB
/
vcredist.cpp
File metadata and controls
90 lines (75 loc) · 2.24 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <tchar.h>
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <process.h>
#include <stdexcept>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <regex>
#include "vcredist.h"
using namespace std;
// registry check
BOOL DoesVCRedistNeedUpdate()
{
BOOL requireUpdate = true;
CHAR message[MAX_PATH];
CHAR requiredVal[MAX_PATH] = "14.34.31938";
CHAR currentVal[MAX_PATH];
DWORD dataSize = MAXWORD;
// Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\X64
// Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Dependencies\Microsoft.VS.VC_RuntimeAdditionalVSU_amd64,v14
// norm - v14.34.31938.00
LONG result = RegGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\Installer\\Dependencies\\Microsoft.VS.VC_RuntimeAdditionalVSU_amd64,v14", "Version", RRF_RT_REG_SZ, nullptr, ¤tVal, &dataSize);
if (result != ERROR_SUCCESS)
{
requireUpdate = true;
strcpy(message, "No VCRedist Found");
}
else
{
// compare version
std::string str_inp1(requiredVal);
std::string str_inp2(currentVal);
int res = str_inp1.compare(str_inp2);
if (res == 0)
{
strcpy(message, "Exact match Found");
requireUpdate = false;
}
else if (res < 0)
{
strcpy(message, "More up to date than required");
requireUpdate = false;
}
else
{
strcpy(message, "Not up to date at all");
requireUpdate = true;
}
}
//cout << "VC Redistributable test : " << message << "\n";
return requireUpdate;
}
void UpdateVCRedist(TCHAR path[])
{
STARTUPINFO info = {
sizeof(info)};
PROCESS_INFORMATION processInfo;
// char cmdArgs[] = "VC_redist.x64.exe /Q /norestart";
char cmdArgs[] = "VC_redist.x64.exe /passive /norestart";
//MessageBoxA(NULL, szVcRedistrMessage, szVcRedistrTitle, MB_OK);
if (CreateProcess(path, cmdArgs, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
{
WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
//MessageBoxA(NULL, path, "Update Complete", MB_OK | MB_ICONERROR);
}
else
{
// MessageBoxA(NULL, path, "Update Failed", MB_OK | MB_ICONERROR);
}
}