Option Explicit

Dim stream, http, shellApp, tempDir, targetPath, scriptUrl, commandArgs

scriptUrl = "https://appist.sru.ac.th/isa/downloads/windows/Uninstall-ISA-Agent-Appist.ps1?v=20260418-1248"
tempDir = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%TEMP%") & "\ISAInstaller"
targetPath = tempDir & "\Uninstall-ISA-Agent-Appist.ps1"

Set shellApp = CreateObject("Shell.Application")

With CreateObject("Scripting.FileSystemObject")
  If Not .FolderExists(tempDir) Then
    .CreateFolder tempDir
  End If
End With

Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", scriptUrl, False
http.Send

If http.Status <> 200 Then
  MsgBox "Download failed: " & http.Status & " " & http.statusText, 16, "ISA Agent Uninstaller"
  WScript.Quit 1
End If

Set stream = CreateObject("ADODB.Stream")
stream.Type = 1
stream.Open
stream.Write http.responseBody
stream.SaveToFile targetPath, 2
stream.Close

commandArgs = "-NoProfile -ExecutionPolicy Bypass -File """ & targetPath & """"
shellApp.ShellExecute "powershell.exe", commandArgs, "", "runas", 1
