简体   繁体   English

如何编写将继续检查应用程序是否未运行并停止检查应用程序是否正在运行的 vbscript

[英]How to write a vbscript that will keep on checking if an application is not running and will stop checking if the app is running

I'm currently a beginner in learning code of vbscript.我目前是学习 vbscript 代码的初学者。 I want this code to run a batch file silently in the background, which will then check if the process "DesktopHut.exe" is running, it will WshShell.AppActivate Desktop.exe and minimize it.我希望此代码在后台静默运行批处理文件,然后检查进程“DesktopHut.exe”是否正在运行,它将 WshShell.AppActivate Desktop.exe 并将其最小化。 If "DesktopHut.exe" is not running.如果“DesktopHut.exe”未运行。 I want the code to loop the checking until it is running.我希望代码循环检查直到它运行。 Essentially here is my code:基本上这里是我的代码:

Dim i
Dim strComputer
Dim FindProc

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\Users\Vincent Buenaventura\Documents\Visualizer On and Off Bat\Visualizer ON" & Chr(34), 0

strComputer = "."

FindProc = "DesktopHut.exe"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select Name from Win32_Process WHERE Name LIKE '" & FindProc & "%'")

Do Until colProcessList.count>0
WshShell.AppActivate("DesktopHut.com App For Live Wallpaper")
WshShell.SendKeys "% n"    
loop

Set Wshell = nothing
WScript.Quit

It somehow works but the loop won't end at all.它以某种方式起作用,但循环根本不会结束。 If anyone can help me fix the code above, it would be an honor.如果有人能帮我修复上面的代码,那将是一种荣幸。 I'm researching all I can just to replace this code, since my PC does not always run the application on time, so it ends up not minimizing the application.我正在研究所有我可以替换的代码,因为我的电脑并不总是按时运行应用程序,所以它最终不会最小化应用程序。 Which is a bit annoying everytime I start up the PC.每次启动PC时都会有点烦人。

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\Users\Vincent Buenaventura\Documents\Visualizer On and Off Bat\Visualizer ON" & Chr(34), 0
WScript.Sleep 2000
WshShell.AppActivate("DesktopHut.com App For Live Wallpaper")
WshShell.SendKeys "% n"
Set Wshell = nothing
WScript.Quit

Quick Side Note: I know that there is this news about DesktopHut having a virus, but as I researched and tested on my own PC.快速旁注:我知道有关于 DesktopHut 有病毒的消息,但是我在自己的 PC 上进行了研究和测试。 It seems like the "virus" is only applicable to the very updated version of DesktopHut on Windows 10.似乎“病毒”仅适用于 Windows 10 上最新版本的 DesktopHut。

I'm currently running on Windows 8.1 Single Language.我目前在 Windows 8.1 Single Language 上运行。

I will use this VBScript:我将使用这个 VBScript:

   Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\Users\Vincent Buenaventura\Documents\Visualizer On and Off Bat\Visualizer ON" & Chr(34)
   sComputerName = "."
   Set objWMIService = GetObject("winmgmts:\\" & sComputerName & "\root\cimv2")
   sQuery = "SELECT * FROM Win32_Process"
   Set objItems = objWMIService.ExecQuery(sQuery)
   For Each objItem In objItems
     If objItem.Name == "DesktopHut.exe" Then
       WshShell.AppActivate "DesktopHut.com App For Live Wallpaper"
        Wscript.Sleep 2000
        WshShell.SendKeys "%n"
     End If
   Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM