From 66b54f3f98f078da01927849d78dc239cbb74587 Mon Sep 17 00:00:00 2001 From: Andrey Starodubtsev Date: Mon, 1 Nov 2021 18:00:10 +0300 Subject: [PATCH] NSIS Error on Windows 11 On Windows 11 Windows Defender sometimes blocks reading exe file, and installer shows "Error launching installer" message. --- Source/exehead/fileform.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/exehead/fileform.c b/Source/exehead/fileform.c index 4e7c67e77b..5fe8ac705e 100644 --- a/Source/exehead/fileform.c +++ b/Source/exehead/fileform.c @@ -186,7 +186,15 @@ const TCHAR * NSISCALL loadHeaders(int cl_flags) GetModuleFileName(NULL, state_exe_path, NSIS_MAX_STRLEN); - g_db_hFile = db_hFile = myOpenFile(state_exe_path, GENERIC_READ, OPEN_EXISTING); + // Windows Defender blocks reading exe file now and then + for (int i = 0; i < 5; ++i) { + Sleep(i * 200); + g_db_hFile = db_hFile = myOpenFile(state_exe_path, GENERIC_READ, OPEN_EXISTING); + if (db_hFile != INVALID_HANDLE_VALUE) + { + break; + } + } if (db_hFile == INVALID_HANDLE_VALUE) { return _LANG_CANTOPENSELF;