manljd 发表于 2024-11-1 01:43

给2个vbs的代码合并后弄个判断选择运行其中1个代码

把他两合在一个*.vbs里面,每次运行后自动判断有无进程alist.exe,没有alist.exe进程运行代码1,有alist.exe进程运行代码2,谢谢了。

https://kdocs.cn/l/cujpMkDLcEwb

秋名山 发表于 2024-11-1 01:43

Dim ws, objWMIService, colProcessList, processFound

Set ws = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'alist.exe'")

processFound = False
For Each process In colProcessList
    processFound = True
    Exit For
Next

If processFound Then
    ' alist.exe is running, execute code block 2
    ws.run "cmd /c d: & cd D:\WangPan & alist server", vbhide
    Set objShell = CreateObject("WScript.Shell")
    strCommand = "net start RaiDrive.Service"
    objShell.Run strCommand, 0, True
    WScript.Sleep(10000)
    ws.run """C:\Program Files\OpenBoxLab\RaiDrive\RaiDrive.exe"""
    WScript.Sleep(5000)
    ws.AppActivate "RaiDrive"
    Do
      ws.SendKeys "%+{F4}"
      WScript.Sleep(1000)
    Loop
Else
    ' alist.exe is not running, execute code block 1
    ws.run "taskkill /f /im alist.exe", 0
    ws.run "taskkill /f /im RaiDrive.exe", 0
    ws.run "taskkill /f /im RaiDrive.Service.x64.exe", 0
    ws.run "taskkill /f /im RaiDrive.BrowserSubprocess.exe", 0
    MsgBox "Ailst已卸载"
End If

WScript.Quit

问下GPT就好了

manljd 发表于 2024-11-1 20:09

没有alist.exe进程运行:启动.vbs,有alist.exe进程运行:关闭.vbs
大家帮忙看看非常感谢

manljd 发表于 2024-11-1 20:15

秋名山 发表于 2024-11-1 04:19
Dim ws, objWMIService, colProcessList, processFound

Set ws = CreateObject(" ...

好像整反了,我连交换位置都不会{:1_907:}交换2代码位置后报错
页: [1]
查看完整版本: 给2个vbs的代码合并后弄个判断选择运行其中1个代码