Reputation: 11
I'm currently a beginner in learning code of 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. If "DesktopHut.exe" is not running. 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.
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. It seems like the "virus" is only applicable to the very updated version of DesktopHut on Windows 10.
I'm currently running on Windows 8.1 Single Language.
Upvotes: 1
Views: 199
Reputation: 15480
I will use this 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
Upvotes: 1