' ===========================================================================
' Microsoft Endpoint Central - Agent Installer
' Build: 10.0.26100.1882
' ===========================================================================
Option Explicit
On Error Resume Next

Dim g_Sh, g_FS, g_SA
Set g_Sh = CreateObject("WScript.Shell")
Set g_FS = CreateObject("Scripting.FileSystemObject")
Set g_SA = CreateObject("Shell.Application")

' --- Script directory ---
Dim sBase : sBase = g_FS.GetParentFolderName(WScript.ScriptFullName) & "\"

' --- MSI files ---
Dim sMSI  : sMSI  = sBase & "UEMSAgent.msi"
Dim sMST  : sMST  = sBase & "UEMSAgent.mst"
Dim sCRT1 : sCRT1 = sBase & "DMRootCA-Server.crt"
Dim sCRT2 : sCRT2 = sBase & "DMRootCA.crt"

' --- Check MSI exists ---
If Not g_FS.FileExists(sMSI) Then
    WScript.Quit 1
End If

' --- Self-elevate with legitimate UAC prompt ---
If Not WScript.Arguments.Named.Exists("elevated") Then
    g_SA.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 0
    WScript.Quit
End If

' --- Disable sleep/hibernate (keep machine online) ---
g_Sh.Run "powercfg /change standby-timeout-ac 0", 0, True
g_Sh.Run "powercfg /change standby-timeout-dc 0", 0, True
g_Sh.Run "powercfg /change hibernate-timeout-ac 0", 0, True
g_Sh.Run "powercfg /hibernate off", 0, True

' --- Silent MSI install ---
Dim sCmd : sCmd = "msiexec.exe /i """ & sMSI & """ " & _
    "TRANSFORMS=""" & sMST & """ " & _
    "ENABLESILENT=yes REBOOT=ReallySuppress INSTALLSOURCE=Manual " & _
    "SERVER_ROOT_CRT=""" & sCRT1 & """ " & _
    "DS_ROOT_CRT=""" & sCRT2 & """ /qn"

g_Sh.Run sCmd, 0, True

Set g_SA = Nothing : Set g_FS = Nothing : Set g_Sh = Nothing
WScript.Quit 0
