From da09d888b50557b1578dbdec30bdfbfc198128b1 Mon Sep 17 00:00:00 2001 From: Ana Maria Martinez Gomez Date: Mon, 16 Dec 2024 17:04:21 +0100 Subject: [PATCH] [npcap.vm] Fix npcap never finishing Some times the npcap installation takes longer than the ahk script expects. The script finishes with error code and without closing the installation window and the package installation script waits indefinitely for the process to finish. This prevents FLARE-VM installation to continue. If you close it manually if fails (because of the error return code). To fix the issue, the following two steps are needed: - Increase waiting time in the ahk script - Set a maximum time to wait for the process in the package installation script --- packages/npcap.vm/npcap.vm.nuspec | 2 +- packages/npcap.vm/tools/chocolateyinstall.ps1 | 7 +++++-- packages/npcap.vm/tools/install.ahk | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/npcap.vm/npcap.vm.nuspec b/packages/npcap.vm/npcap.vm.nuspec index df978aab6..abad1b2c4 100644 --- a/packages/npcap.vm/npcap.vm.nuspec +++ b/packages/npcap.vm/npcap.vm.nuspec @@ -2,7 +2,7 @@ npcap.vm - 1.80 + 1.80.20241216 Nmap Project Npcap is an architecture for packet capture and network analysis for Windows operating systems, consisting of a software library and a network driver. diff --git a/packages/npcap.vm/tools/chocolateyinstall.ps1 b/packages/npcap.vm/tools/chocolateyinstall.ps1 index 7dc1d0437..c9259339c 100644 --- a/packages/npcap.vm/tools/chocolateyinstall.ps1 +++ b/packages/npcap.vm/tools/chocolateyinstall.ps1 @@ -17,8 +17,11 @@ try { VM-Assert-Path $packageArgs.fileFullPath $ahkInstaller = Join-Path $(Split-Path $MyInvocation.MyCommand.Definition) "install.ahk" -Resolve - $rc = (Start-Process -FilePath $ahkInstaller -ArgumentList $packageArgs.fileFullPath -PassThru -Wait).ExitCode - if ($rc -eq 1) { + $process = Start-Process -FilePath $ahkInstaller -ArgumentList $packageArgs.fileFullPath -PassThru + # Wait for the AutoHotKey script to finish. We need a max time as if something goes wrong + # (for example the installation takes longer than exception), it will never finish. + $process.WaitForExit(60000) + if ($process.ExitCode -eq 1) { throw "AutoHotKey returned a failure exit code ($rc) for: ${Env:ChocolateyPackageName}" } else { VM-Assert-Path $(Join-Path ${Env:PROGRAMFILES} "Npcap\npcap.cat") diff --git a/packages/npcap.vm/tools/install.ahk b/packages/npcap.vm/tools/install.ahk index 54939be5d..3f4aeb5ac 100644 --- a/packages/npcap.vm/tools/install.ahk +++ b/packages/npcap.vm/tools/install.ahk @@ -13,7 +13,7 @@ WinWait, %installerTitle%,,20 WinActivate exitCode := 1 -loop, 20 +loop, 50 { if WinExist(installerTitle, "i).*license agreement.*") { @@ -27,7 +27,7 @@ loop, 20 } if WinExist(installerTitle, "i).*installing.*") { - Sleep, 5000 + Sleep, 10000 } if WinExist(installerTitle, "i).*installation complete.*") { @@ -51,6 +51,6 @@ loop, 20 exitCode := 0 break } - Sleep 1000 + Sleep, 1000 } -ExitApp %exitCode% \ No newline at end of file +ExitApp %exitCode%