Skip to content

Commit

Permalink
feat: Update VBS with expected features
Browse files Browse the repository at this point in the history
Permit MSI package installation from current folder
Improve VBS deployment with a check if installed correctly or retry
Fix uninstallFusionInventoryAgent() function indentation
Closes #429, #505
  • Loading branch information
g-bougard committed Oct 2, 2023
1 parent a396510 commit 9fbc65f
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 41 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ packaging:
* fix #446: Always add Sys::Hostname dependency to rpm packaging
* fix #493: Add support for CONFIG=reset option for MSI Installer

contrib:
* fix #429: Permit MSI package installation from current folder
* fix #505: [Idea] Improve VBS deployment with a check if installed correctly or retry

1.5 Wed, 21 Jun 2023

core:
Expand Down
139 changes: 98 additions & 41 deletions contrib/windows/glpi-agent-deployment.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -214,41 +214,41 @@ Function hasOption(opt)
End Function

Function uninstallFusionInventoryAgent()
Dim Uninstall, getValue

' Try to get SERVER and LOCAL from FIA configuration in registry if needed
If not hasOption("SERVER") then
On error resume next
getValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\FusionInventory-Agent\server")
If err.number = 0 And getValue <> "" then
SetupOptions = SetupOptions & " SERVER='" & getValue & "'"
End If
End If
If not hasOption("LOCAL") then
On error resume next
getValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\FusionInventory-Agent\local")
If err.number = 0 And getValue <> "" then
SetupOptions = SetupOptions & " LOCAL='" & getValue & "'"
End If
End If

' Verify normal case
On error resume next
Uninstall = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\FusionInventory-Agent\UninstallString")
If err.number = 0 then
WshShell.Run "CMD.EXE /C net stop FusionInventory-Agent",0,True
WshShell.Run "CMD.EXE /C """ & Uninstall & """ /S /NOSPLASH",0,True
WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles%\FusionInventory-Agent"" /S /Q",0,True
End If

' Verify FIA x86 is installed on x64 OS
On error resume next
Uninstall = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\FusionInventory-Agent\UninstallString")
If err.number = 0 then
WshShell.Run "CMD.EXE /C net stop FusionInventory-Agent",0,True
WshShell.Run "CMD.EXE /C """ & Uninstall & """ /S /NOSPLASH",0,True
WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles(x86)%\FusionInventory-Agent"" /S /Q",0,True
End If
Dim Uninstall, getValue

' Try to get SERVER and LOCAL from FIA configuration in registry if needed
If not hasOption("SERVER") then
On error resume next
getValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\FusionInventory-Agent\server")
If err.number = 0 And getValue <> "" then
SetupOptions = SetupOptions & " SERVER='" & getValue & "'"
End If
End If
If not hasOption("LOCAL") then
On error resume next
getValue = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\FusionInventory-Agent\local")
If err.number = 0 And getValue <> "" then
SetupOptions = SetupOptions & " LOCAL='" & getValue & "'"
End If
End If

' Verify normal case
On error resume next
Uninstall = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\FusionInventory-Agent\UninstallString")
If err.number = 0 then
WshShell.Run "CMD.EXE /C net stop FusionInventory-Agent",0,True
WshShell.Run "CMD.EXE /C """ & Uninstall & """ /S /NOSPLASH",0,True
WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles%\FusionInventory-Agent"" /S /Q",0,True
End If

' Verify FIA x86 is installed on x64 OS
On error resume next
Uninstall = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\FusionInventory-Agent\UninstallString")
If err.number = 0 then
WshShell.Run "CMD.EXE /C net stop FusionInventory-Agent",0,True
WshShell.Run "CMD.EXE /C """ & Uninstall & """ /S /NOSPLASH",0,True
WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles(x86)%\FusionInventory-Agent"" /S /Q",0,True
End If
End Function

Function AdvanceTime(nMinutes)
Expand Down Expand Up @@ -459,6 +459,63 @@ Function ShowMessage(strMessage)
End If
End Function

Function MsiServerAvailable()
Dim loopCount, objWMIService, oMsiServer, oServicePath, errExecMethod
MsiServerAvailable = false
Const maxLoops = 120
loopCount = 0
'Wait maximum 2 minutes to get MsiServer service available
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Do While loopCount < maxLoops
If loopCount > 0 Then
WScript.Sleep 1000
End If
Set oMsiServer = GetObject("winmgmts:Win32_Service='MsiServer'")
If oMsiServer.State = "Stopped" Then
MsiServerAvailable = true
Exit Function
End If
Set oServicePath = oMsiServer.Path_
Set errExecMethod = objWMIService.ExecMethod(oServicePath, "StopService")
'StopService method should fail with ReturnValue set to 5 on MsiServer business
If errExecMethod.ReturnValue = 0 Then
MsiServerAvailable = true
Exit Function
End If
loopCount = loopCount + 1
Loop
End Function

Function MsiExec(strOptions)
Dim loopCount
Const maxLoops = 3
loopCount = 0
Do While loopCount < maxLoops
If loopCount > 0 Then
ShowMessage("Next attempt in 30 seconds...")
WScript.Sleep 30000
End If
If MsiServerAvailable() Then
ShowMessage("Running: MsiExec.exe " & strOptions)
MsiExec = WshShell.Run("MsiExec.exe " & strOptions, 0, True)
' Error 1618 occurs on MsiServer business, we should only retry on that error
If MsiExec <> 1618 Then
Exit Do
End If
Else
MsiExec = 1618
End If
loopCount = loopCount + 1
Loop
If MsiExec = 0 Then
ShowMessage("Deployment done!")
ElseIf MsiExec = 1618 Then
ShowMessage("Deployment failed: MSI Installer is busy!")
Else
ShowMessage("Deployment failed! (Err=" & MsiExec & ")")
End If
End Function

'
'
' MAIN
Expand Down Expand Up @@ -543,18 +600,18 @@ If bInstall Then
If SaveWebBinary(SetupLocation, Setup) Then
strCmd = WshShell.ExpandEnvironmentStrings("%ComSpec%")
strTempDir = WshShell.ExpandEnvironmentStrings("%TEMP%")
ShowMessage("Running: MsiExec.exe " & strInstallOrRepair & " """ & strTempDir & "\" & Setup & """ " & SetupOptions)
WshShell.Run "MsiExec.exe " & strInstallOrRepair & " """ & strTempDir & "\" & Setup & """ " & SetupOptions, 0, True
MsiExec(strInstallOrRepair & " """ & strTempDir & "\" & Setup & """ " & SetupOptions)
ShowMessage("Scheduling: DEL /Q /F """ & strTempDir & "\" & Setup & """")
WshShell.Run "AT.EXE " & AdvanceTime(nMinutesToAdvance) & " " & strCmd & " /C ""DEL /Q /F """"" & strTempDir & "\" & Setup & """""", 0, True
ShowMessage("Deployment done!")
Else
ShowMessage("Error downloading '" & SetupLocation & "\" & Setup & "'!")
End If
Else
ShowMessage("Running: MsiExec.exe " & strInstallOrRepair & " """ & SetupLocation & "\" & Setup & """ " & SetupOptions)
WshShell.Run "MsiExec.exe " & strInstallOrRepair & " """ & SetupLocation & "\" & Setup & """ " & SetupOptions, 0, True
ShowMessage("Deployment done!")
'Don't include path if empty or set to current folder
If SetupLocation <> "" And SetupLocation <> "." Then
Setup = SetupLocation & "\" & Setup
End If
MsiExec(strInstallOrRepair & " """ & Setup & """ " & SetupOptions)
End If
Else
ShowMessage("It isn't needed the installation of '" & Setup & "'.")
Expand Down

0 comments on commit 9fbc65f

Please sign in to comment.