From dcc0eb72a04ba2c0c83d29bd621a7f66acce0a23 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 20 Jan 2023 10:02:27 +0100 Subject: fetcher: add /noprompt switch Deploying WireGuard MSI using Microsoft Endpoint Manager (aka MS Intune) falls short with poor Microsoft Endpoint Manager support: no ARM64 support, requires multiple per-architecture deployments... Fetcher proves super-useful for automating WireGuard install. It contains platform selection logic, MSI download, integrity check... However, automated installation is an unattended process and the wireguard-installer.exe must not block the process for any user prompts. Signed-off-by: Simon Rozman --- installer/fetcher/fetcher.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/installer/fetcher/fetcher.c b/installer/fetcher/fetcher.c index b3fbc994..5c688997 100644 --- a/installer/fetcher/fetcher.c +++ b/installer/fetcher/fetcher.c @@ -23,7 +23,7 @@ #include "constants.h" static char msi_filename[MAX_PATH]; -static volatile bool msi_filename_is_set; +static volatile bool msi_filename_is_set, prompts = true; static volatile size_t g_current, g_total; static HWND progress; static HANDLE filehandle = INVALID_HANDLE_VALUE; @@ -208,7 +208,7 @@ out: if (security_attributes.lpSecurityDescriptor) LocalFree(security_attributes.lpSecurityDescriptor); - if (ret) { + if (ret && prompts) { ShowWindow(progress, SW_SHOWDEFAULT); if (MessageBoxA(progress, "Something went wrong when downloading the WireGuard installer. Would you like to open your web browser to the MSI download page?", "Download Error", MB_YESNO | MB_ICONWARNING) == IDYES) ShellExecuteA(progress, NULL, "https://" server msi_path, NULL, NULL, SW_SHOWNORMAL); @@ -285,6 +285,20 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar return DefSubclassProc(hWnd, uMsg, wParam, lParam); } +static void parse_command_line(void) +{ + LPWSTR *argv; + int argc; + argv = CommandLineToArgvW(GetCommandLineW(), &argc); + if (!argv) + return; + for (int i = 1; i < argc; ++i) { + if (wcsicmp(argv[i], L"/noprompt") == 0) + prompts = false; + } + LocalFree(argv); +} + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow) { MSG msg; @@ -297,6 +311,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, if (!SetDllDirectoryA("") || !SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32)) return 1; + parse_command_line(); + InitCommonControlsEx(&(INITCOMMONCONTROLSEX){ .dwSize = sizeof(INITCOMMONCONTROLSEX), .dwICC = ICC_PROGRESS_CLASS }); progress = CreateWindowExA(0, PROGRESS_CLASS, "WireGuard Installer", -- cgit v1.2.3-59-g8ed1b