I have a .vbs-Script that is running in the background endlessly. This script does not have any way for the user to interact with it; a regular user won't even notice something is running in the background. Now I need to be able to end this Script at any time.
So, now I'm searching for the easiest way to be able to cancel this .vbs-Script without using the Task Manager, other Tools or additional Scripts and without typing something like this to PowerShell or the Command Prompt:
PowerShell: Stop-Process -Name wscript
Command Prompt: Taskkill /IM wscript
I tried running a .cmd-Script that simply runs the .vbs-Script. I hoped I'd be able to end the .vbs-Script alongside with the .cmd either by pressing CTRL+C or by closing the Command Prompt, but I've tested it, and it didn't work this way.
So I googled a little bit and found out it's possible to create a visible Tray-Icon for a running .vbs-Script that would allow right-clicking it to close it. But I can't get it to work. Following you can see the code, I tried. The first three lines are for the Tray-Icon, line four to nine is the actual script that is running in the background:
Public Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Caffeinate" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim objResult
Set objShell = WScript.CreateObject("WScript.Shell")
Do While True
objResult = objShell.sendkeys("{NUMLOCK}{NUMLOCK}")
Wscript.Sleep (6000)
Loop
Does someone know how to make use of a System Tray-Icon for a vbs.Script?
Alternatively, any other "easy-to-use" way to cancel a .vbs-Script like that would be super nice.
Kind regards,
Kevin
wscript.exe
, which uses windows for input and output; andcscript.exe
which uses a console window. By default,.vbs
files are run withwscript.exe
. If you force the script to be run withcscript.exe
-- e.g. with a batch file, or even another script -- you'll end up with a visible window which the user can close at any time.