-
Notifications
You must be signed in to change notification settings - Fork 121
/
Install_.Net_Framework_from_the_command_line.cpp
164 lines (148 loc) · 4.53 KB
/
Install_.Net_Framework_from_the_command_line.cpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <afx.h>
#include <Windows.h>
BOOL CALLBACK EnumChildWindowProc(HWND Child_hWnd, LPARAM lParam)
{
WCHAR szTitle[1024];
if (Child_hWnd)
{
GetWindowText(Child_hWnd, szTitle, sizeof(szTitle));
if (wcscmp(szTitle, L"&Install") == 0)
{
printf("[+] Catch it!\n");
printf("[*] Handle: %08X\n", Child_hWnd);
printf("[*] Caption: %ws\n", szTitle);
printf("[*] 5.Enable the Install button.\n");
EnableWindow(Child_hWnd, TRUE);
printf("[*] 6.Send the click command to &Install.\n");
::PostMessage(Child_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(0,0));
::PostMessage(Child_hWnd, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(0, 0));
printf("[*] 7.You should wait for the installation to complete.\n");
}
return true;
}
return false;
}
BOOL CALLBACK EnumChildWindowProc2(HWND Child_hWnd, LPARAM lParam)
{
WCHAR szTitle[1024];
if (Child_hWnd)
{
GetWindowText(Child_hWnd, szTitle, sizeof(szTitle));
if (wcscmp(szTitle, L"&Finish") == 0)
{
printf("[+] Catch it!\n");
printf("[*] Handle: %08X\n", Child_hWnd);
printf("[*] Caption: %ws\n", szTitle);
printf("[*] 8.Send the click command to &Finish.\n");
::PostMessage(Child_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(0, 0));
::PostMessage(Child_hWnd, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(0, 0));
}
else if (wcscmp(szTitle, L"Restart &Later") == 0)
{
printf("[+] Catch it!\n");
printf("[*] Handle: %08X\n", Child_hWnd);
printf("[*] Caption: %ws\n", szTitle);
printf("[*] 9.Send the click command to Restart &Later.\n");
::PostMessage(Child_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(0, 0));
::PostMessage(Child_hWnd, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(0, 0));
printf("[*] 10.All done.\n");
printf("[*] You need to wait for the system to reboot to complete the installation.\n");
exit(0);
}
return true;
}
return false;
}
int _tmain(int argc, _TCHAR *argv[])
{
if (argc != 3)
{
printf("\nAutomatically install Microsoft .NET Framework 4/4.5/4.5.1 in the background.\n");
printf("Author: 3gstudent\n");
printf("You can get Microsoft .NET Framework 4 (Standalone Installer) from:\n");
printf(" https://www.microsoft.com/en-US/Download/confirmation.aspx?id=17718\n");
printf("You can get Microsoft .NET Framework 4.5 (Web Installer) from:\n");
printf(" https://www.microsoft.com/en-us/download/details.aspx?id=30653\n");
printf("You can get Microsoft .NET Framework 4.5.1 (Offline Installer) from:\n");
printf(" https://www.microsoft.com/en-us/download/details.aspx?id=40779\n");
printf("Usage:\n");
printf(" %ws <setup file path> <.NET Framework version>\n", argv[0]);
printf("Eg.\n");
printf(" %ws dotNetFx40_Full_x86_x64.exe 4\n", argv[0]);
printf(" %ws dotNetFx45_Full_setup.exe 4.5\n", argv[0]);
printf(" %ws NDP451-KB2858728-x86-x64-AllOS-ENU.exe 4.5.1\n", argv[0]);
return 0;
}
WCHAR szWindow[48] = {0};
if (wcscmp(argv[2], L"4") == 0)
{
wcscpy_s(szWindow, L"Microsoft .NET Framework 4 Setup");
}
else if (wcscmp(argv[2], L"4.5") == 0)
{
wcscpy_s(szWindow, L"Microsoft .NET Framework 4.5");
}
else if (wcscmp(argv[2], L"4.5.1") == 0)
{
wcscpy_s(szWindow, L"Microsoft .NET Framework 4.5.1");
}
else
{
printf("[!] Wrong parameter]\n");
return 0;
}
printf("[+] Version: %ws\n", szWindow);
printf("[*] 1.Check the installation environment.\n");
HWND hWnd1 = FindWindow(NULL, szWindow);
if (hWnd1 != NULL)
{
printf("[!]Another install is already running.\n");
return 0;
}
printf("[*] 2.Run the setup file.\n");
PROCESS_INFORMATION pi;
STARTUPINFO si;
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.cbReserved2 = NULL;
si.lpReserved2 = NULL;
if (CreateProcess(NULL, argv[1], NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) == 0)
{
printf("[!] Wrong path.\n");
return 0;
}
printf("[*] 3.Try to hide the main window.\n");
while(1)
{
HWND hWnd2 = FindWindow(NULL, szWindow);
ShowWindow(hWnd2, SW_HIDE);
if (hWnd2 != NULL)
{
printf("[+] Catch it!\n");
break;
}
Sleep(100);
}
printf("[*] Wait 10 seconds.\n");
Sleep(10000);
HWND hWnd3 = FindWindow(NULL, szWindow);
if (hWnd3 == NULL)
{
printf("[!] I can't find the main window.\n");
return 0;
}
printf("[*] 4.Try to eunm the child window.\n");
EnumChildWindows(hWnd3, EnumChildWindowProc, 0);
printf("[*] Waiting for the installation process...\n");
while (1)
{
HWND hWnd4 = FindWindow(NULL, szWindow);
EnumChildWindows(hWnd4, EnumChildWindowProc2, 0);
Sleep(100);
}
return 0;
}