Last active
May 3, 2024 07:33
-
-
Save FrendaWinter/bb670dd1c65b2ad48c7247bd266b4eba to your computer and use it in GitHub Desktop.
Download MSi file and install it (Replace the code with correct URL and silent install param, run as administrator if needed)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <windows.h> | |
#include <urlmon.h> | |
#pragma comment(lib, "urlmon.lib") | |
int main() | |
{ | |
std::string downloadUrl = "https://www.uvnc.eu/download/1400/UltraVnc_1409_X64.msi"; // Replace with the actual download URL | |
std::string filePath = "D:\\Download\\UltraVnc_1409_X64.msi"; // Replace with the desired download path | |
HRESULT hr = URLDownloadToFile(NULL, downloadUrl.c_str(), filePath.c_str(), 0, NULL); | |
if (SUCCEEDED(hr)) | |
{ | |
std::cout << "File downloaded successfully!" << std::endl; | |
// Launch MSI installation | |
STARTUPINFO si = {sizeof(si)}; | |
PROCESS_INFORMATION pi; | |
// Run installation (Add more params if needed) | |
if (CreateProcess(NULL, const_cast<char *>(("msiexec.exe /i " + filePath).c_str()), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) | |
{ | |
WaitForSingleObject(pi.hProcess, INFINITE); | |
CloseHandle(pi.hProcess); | |
CloseHandle(pi.hThread); | |
std::cout << "Installation complete." << std::endl; | |
} | |
else | |
{ | |
std::cerr << "Failed to launch MSI installation." << std::endl; | |
} | |
// Delete the downloaded file (optional) | |
DeleteFile(filePath.c_str()); | |
} | |
else | |
{ | |
std::cerr << "Download failed: " << std::hex << hr << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment