Last active
July 2, 2023 05:13
-
-
Save Dobby233Liu/1b2b32a9f2f85863938e007021998f7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dim Wsh, Fs, WMIServ | |
Set Wsh = CreateObject("WScript.Shell") | |
Set Fs = CreateObject("Scripting.FileSystemObject") | |
Set WMIServ = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") | |
MainDir = Fs.GetFile(WScript.ScriptFullName).ParentFolder.Path | |
Function HasArg(TargetArg) | |
HasArg = False | |
For Each Arg in WScript.Arguments | |
If LCase(Arg) = "/" & TargetArg Then | |
HasArg = True | |
End If | |
Next | |
End Function | |
Function MakeExeLoc(BasicLoc) | |
MakeExeLoc = """" & MainDir & "\" & BasicLoc & ".exe""" | |
End Function | |
Function GetAria2Exe() | |
GetAria2Exe = "aria2c_64" | |
Exit Function | |
Dim Processor | |
Set Processor = WMIServ.ExecQuery("SELECT * FROM Win32_Processor WHERE DeviceID = ""CPU0""").ItemIndex(0) | |
If Processor.Architecture = 0 or Processor.Architecture = 9 Then | |
GetAria2Exe = "aria2c_" & CStr(Processor.AddressWidth) | |
Else | |
Err.Raise vbObjectError + 1, "Start2.vbs", "Unsupported processor" | |
End If | |
End Function | |
' https://stackoverflow.com/questions/32963635/how-to-check-whether-a-process-is-running-using-vb-script | |
Function IsProcessRunning(ProcessName) | |
InName = """"& ProcessName & ".exe""" | |
Dim MatchingProcesses | |
Set MatchingProcesses = WMIServ.ExecQuery("SELECT * FROM Win32_Process WHERE Name = " & InName) | |
If MatchingProcesses.Count = 0 Then | |
IsProcessRunning = False | |
Else | |
IsProcessRunning = True | |
End If | |
End Function | |
Sub Run(Args, WindowStyle, WaitOnReturn) | |
If VarType(Args) >= vbArray Then | |
TargetStr = Join(Args, " ") | |
Else | |
TargetStr = Args | |
End If | |
Wsh.Run TargetStr, WindowStyle, WaitOnReturn | |
End Sub | |
Function Main() | |
If HasArg("help") or HasArg("?") Then | |
WScript.Echo _ | |
"Start2.vbs [/webui] [/help]" & vbCrLf & _ | |
" /help - displays this message" & vbCrLf & _ | |
" /webui - starts Aria2 WebUI for baiduwp-php instead of AriaNg Native" | |
Main = 0 | |
Exit Function | |
End If | |
SrvName = GetAria2Exe() | |
GUIName = "AriaNg Native" | |
SrvExe = MakeExeLoc(SrvName) | |
GUIExe = MakeExeLoc("AriaNg_Native\" & GUIName) | |
SrvArgs = Array(SrvExe, "--enable-rpc") | |
GUIArgs = Array(GUIExe) | |
WebUIURL = "https://imwcr.cn/api/webui-aria2/" | |
If Not IsProcessRunning(SrvName) Then | |
' start service | |
Run SrvArgs, vbHide, False | |
End If | |
' start GUI | |
If Not HasArg("webui") Then | |
Run GUIArgs, vbShow, False | |
Else | |
Run WebUIURL, vbShow, False | |
End If | |
Main = 0 | |
End Function | |
WScript.Quit Main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment