A
A
Artyom2018-11-02 15:28:45
cmd/bat
Artyom, 2018-11-02 15:28:45

Question on vbs, how to close a certain process when it appears in the task manager?

Hello. There is such a vbs script that closes a certain process from the task manager.
Here is his code
Dim oShell : Set oShell = CreateObject("WScript.Shell")
' Kill notepad '
oShell.Run "taskkill /im update_notepad.exe", , True
The code fires if there is a process in the task manager, if not, it closes with an error .
The problem is that the process that needs to be closed appears in a minute, and the script is launched earlier, that is, it just turns off.
Is it possible to do something so that the script repeats the actions until the process appears, and after a successful closure, completes the work, while preferably without a running black window with the task?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2018-11-02
@res2001

You can get rid of the console window by running the script with wscript:
wscript <script name> The
console window from taskkill can be hidden by running the command like this:
oShell.Run "taskkill /im update_notepad.exe", 1, True Regarding
waiting: the Run method of the WScript object. Shell returns the return code of the application being launched.
If taskkill itself can signal the work done, then you can call taskkill in a loop and analyze the return code until it becomes clear from the code that the process has been deleted.
You need to figure out the taskkill return codes yourself, you can do this using a simple batch file, analyzing the errorlevel after calling taskkill. I have not seen taskkill return codes anywhere in the documentation.
If taskkill does not use return codes (many standard Windows utilities neglect this feature), then the task becomes more complicated.
One option is to parse the output of taskkill, with find or findstr , and catch their return code (these utilities report exactly in the return code that the string was found or not found).
Another option is to first find out if your process is running using tasklist and only then call taskkill.
And don't forget to pause between taskkill calls. this carousel without pauses will eat up a lot of CPU time from you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question