Skip to content

Commit

Permalink
fetcher: add /noprompt switch
Browse files Browse the repository at this point in the history
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 <simon@rozman.si>
  • Loading branch information
rozmansi committed Jan 23, 2023
1 parent 004c22c commit dcc0eb7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions installer/fetcher/fetcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -208,7 +208,7 @@ static DWORD __stdcall download_thread(void *param)
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);
Expand Down Expand Up @@ -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;
Expand All @@ -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",
Expand Down

0 comments on commit dcc0eb7

Please sign in to comment.