Turn off a VBScript program while it is running - vbscript

(This is a .vbs program) I am trying to make a message bot for a program but I came up with a problem where if you set the time for too long, and set number of messages too high, you can't stop the program easily and have to deal with your message being typed over and over again until it is finished. Is there a way to add an option while it is running to stop the message from being typed?
Here is the code:
set shell = createobject ("wscript.shell")
strtext = inputbox ("Type the message you like to type")
strtimes = inputbox ("How many times would you like to type this message?")
strspeed = inputbox ("How fast do you like to message? (1000 = one per sec, 100 = 10 per sec etc)")
strtimeneed = inputbox ("How many SECONDS do you need to get to your input box?")
If not isnumeric (strtimes & strspeed & strtimeneed) then
msgbox "You entered something else then a number on Times, Speed and/or Time need. Closing program"
wscript.quit
End If
strtimeneed2 = strtimeneed * 1000
do
msgbox "You have " & strtimeneed & " seconds to get to your input area where you are going to message."
wscript.sleep strtimeneed2
shell.sendkeys ("Hello" & "{enter}")
for i=0 to strtimes
shell.sendkeys (strtext & "{enter}")
wscript.sleep strspeed
Next
shell.sendkeys ("Bye" & "{enter}")
wscript.sleep strspeed * strtimes / 10
returnvalue=MsgBox ("Want to send the messages again with the same info?",36)
If returnvalue=6 Then
Msgbox "Ok Messagebot will activate again"
End If
If returnvalue=7 Then
msgbox "Messaging is shutting down"
wscript.quit
End IF
loop

You can just set up a shortcut to terminate all running wscript.exe processes. Click right mouse button on the desktop, in context menu choose New - Shortcut:
Enter %comspec% /c taskkill /f /im wscript.exe as location and click Next:
Enter a name you like and click Finish:
Also you may assign hot keys in shortcut properties.

Related

VBScript loops in section of sub that does not contain looping code

Windows 10 Enterprise
Version 20H2
I am writing a VBScript that handles a print to PDF dialogue window.
The goal:
Detect that the printer dialogue window is open (using a loop that continuously checks)
If/when detected, handle the dialogue (send the filename, send the file path, click "print" to finish)
The problem: for some reason, the sub endlessly loops through an If statement. I don't understand why the code is looping through a section containing no loop code.
The code basically sends the same keys in a loop over and over again within the dialogue window, never completing the If statement.
As a small aside, I think the sendKeys command I use to close the dialogue is incorrect, but that should not cause an IF statement to loop.
Code (go to the section indicated by "#"'s to see where I am having issues):
Sub handlePrintDial()
iSeconds = 20
'================================================================================
' Set time variables
'================================================================================
tNow = now()
tFuture = DateAdd("s",iSeconds,tNow)
'================================================================================
' Set other objects
'================================================================================
Set WshShell = CreateObject("WScript.Shell")
sApp = "Save Print Output As"
sFileName = "This is a test-" & Year(now()) & Month(now()) & Day(now()) & Hour(now()) & Minute(now()) & Second(now())
'================================================================================
' Loop until window opens or time elapses
'================================================================================
Do Until Now() > tFuture
ret = WshShell.AppActivate(sApp)
If ret = True Then
Exit Do
End If
Loop
If ret <> True Then
MsgBox "Printer window not found. Please try again."
Exit Sub
End If
'================================================================================
' If printer window detected, handle window
'================================================================================
WScript.Sleep 500
ret = WshShell.AppActivate(sApp)
'########This is the top of the endless loop####################
If ret = True Then
ret = wshShell.AppActivate(sApp)
' Send filename
WScript.Sleep 2000
wshShell.sendKeys sFileName
WScript.Sleep 2000
' Send file path to save to
wshShell.sendKeys "{F4}"
WScript.Sleep 2000
wshShell.sendKeys "{BS}"
WScript.Sleep 2000
wshShell.sendKeys "^A"
WScript.Sleep 2000
wshShell.sendKeys "{del}"
WScript.Sleep 2000
wshShell.sendKeys "C:\Users\Username\Desktop\closeDialogue.vbs"
WScript.Sleep 2000
' "Click" print to complete the dialogue window
wshShell.sendKeys "{enter}"
WScript.Sleep 2000
wshShell.sendKeys "{enter}"
WScript.Sleep 2000
End If
WScript.Sleep 500
'########This is the bottom of the endless loop####################
WScript.Quit
End Sub
Call handlePrintDial()
Here is the window I am trying to handle:
After some experimentation, I discovered that the sendKeys "{enter}" commands were mysteriously causing the script to execute again (two simultaneous instances of the code running at once, per command line). When I removed Enter keys, the code ran normally without kicking off new instances of the script.
Summary: use sendKeys at your own peril. Specifically, it appears {enter} can cause the code to have unusual problems.

Single Line Input VBS Autotyper

I am currently trying to make an autotyper in VBS and I cannot figure out how to easily input what is to be typed. Right now, this is what my code has to look like:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "notepad"
WScript.sleep 10000
WshShell.SendKeys "H"
WScript.Sleep 100
WshShell.SendKeys "e"
WScript.Sleep 100
WshShell.SendKeys "l"
WScript.Sleep 100
WshShell.SendKeys "l"
WScript.Sleep 100
WshShell.SendKeys "o"
But I really want my code to have all the text that will be auto-typed in just one line instead of me having to repeat the SendKeys for every letter.
I made for you a little example that can type letter by letter as a Typewriter.
Hope this what you are looking for !
strText="Hello ! How are you mate ? Hope that everything is OK !" & vbCrlf &_
"This vbscript is made by Hackoo !"
Call AutoTypeWriter(strText)
'------------------------------------------
Sub AutoTypeWriter(strText)
intPause = 150
Set Ws = CreateObject("WScript.Shell")
'To start Notepad maximized
Ws.Run "Notepad",3
WScript.Sleep 1000
intTextLen = Len(strText)
For x = 1 to intTextLen
strTempText = Mid(strText,x,1)
Ws.Sendkeys strTempText
WScript.Sleep intPause
Next
End Sub
'------------------------------------------
This works for me .. here
strtext = inputbox ("Message (Auto-typer made/coded by bolts)")
strtimes = inputbox ("Message Amount (Amount of messages)")
If not isnumeric (strtimes) then
msgbox "Hint: Use numbers."
wscript.quit
End If
strspeed = inputbox ("Message Speed (How many per second. 1000 = 1 message per second, 100 = 10 messages per second)")
If not isnumeric (strspeed) then
msgbox "Hint: Use numbers."
wscript.quit
End If
strtimeneed = inputbox ("How long before the typing starts. (Seconds)")
If not isnumeric (strtimeneed) then
msgbox "Hint: Use numbers."
wscript.quit
End If
strtimeneed2 = strtimeneed * 1000
do
msgbox "You have " & strtimeneed & " seconds to get to your text area where you are going to type."
wscript.sleep strtimeneed2
shell.sendkeys ("" & "{enter}")
for i=0 to strtimes
shell.sendkeys (strtext & "{enter}")
wscript.sleep strspeed
Next
shell.sendkeys ("" & "{enter}")
wscript.sleep strspeed * strtimes / 10
returnvalue=MsgBox ("Want to type again with the same message, ammount, speed and time?",36)
If returnvalue=6 Then
msgbox "Ok typing will start again in a few seconds."
End If
If returnvalue=7 Then
msgbox "Bolts' lazy auto-typing program is going to sleep."
wscript.quit
End IF
loop

I need some idea to correct this VBS code

Hello everyone.
Hope everyone is fine.
I need help with this code below with the section (comment line) saying "'Help needed from here'":
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime")
For Each objItem in colItems
MsgBox "Welcome to the ALARM tool",0+0,"ALARM tool"
MsgBox "Note: 1) If the computer is given a shutdown or a restart command then the alarm will be disabled. 2) This ALARM tool dosen't support decimals & words. If you will enter a decimal, the elapsed message box will appear without processing the alarm due to the error. If you enter words then an error message will appear.",0+0,"ALARM tool"
thour=InputBox ("Type which hour you want the alarm to elapse in 24-hour format from 0 to 23 inclusive (not 24; instead 0): (E.G: 19, 15)","ALARM tool")
If thour="" Then
MsgBox "The value is empty, so no alarm is set.",16,"ALARM tool"
WScript.Quit
End If
tmin=InputBox ("Type which minute you want the alarm to elapse from 0 to 60 inclusive:","ALARM tool")
If tmin="" Then
MsgBox "The value is empty, so no alarm is set.",16,"ALARM tool"
WScript.Quit
End If
c=InputBox ("Enter your comment; leave it blank if you don't want one:","ALARM tool")
If c="" Then
MsgBox "Time: ''"+thour+":"+tmin+"'' Comment: None",0,"ALARM tool: Preview"
Else
MsgBox "Time: ''"+thour+":"+tmin+"'' Comment: ''"+c+"''",0,"ALARM tool: Preview"
End If
co=MsgBox ("Are you sure?",36,"ALARM tool")
If co="7" Then
MsgBox "Alarm cancelled!!!",0,"ALARM tool"
WScript.Quit
End If
'Help needed from here'
Do
If thour=objItem.Hour Then
If tmin=objItem.Minute Then
If c="" Then
MsgBox "ALARM set to elapse on "+thour+":"+tmin+" has elapsed!!!",0+0,"ALARM set to elapse in "+t
WScript.Quit
Else
MsgBox c,0+0,"ALARM set to elapse in "+t
WScript.Quit
End If
End If
End If
'No more help needed after this'
If Err.Number <> 0 Then
MsgBox "There's an error while setting the alarm. Maybe you typed words or it's an internal error. Please try again. Sorry for the inconvenience.",0,"ALARM tool"
WScript.Quit
End If
Loop
Next
You can give me the answer while even use it for yourself.Topic: Alarm for specific timeI will say thanks for helping me and it will be a very good help.

How to make a vbs spam bot?

I'm trying to make a spam bot, the basic function works fine but the counter isn't. It should go from and imputed number [i] and stop at another [count] and if count < i; it should count backwards. But it is not stopping at count, it keeps going, It won't count backwards either.
set shl = createobject("wscript.shell")
spam = inputbox("What do you want to spam?")
if spam = "/count" then
i = inputbox("Start at what number?")
count = inputbox("Stop at what number?")
wscript.sleep 2500
if count > i then
do while count > i
shl.sendkeys i
wscript.sleep 10
shl.sendkeys "{ENTER}"
wscript.sleep 10
i = i + 1
loop
elseif count < i then
do while count < i
shl.sendkeys i
wscript.sleep 10
shl.sendkeys "{ENTER}"
wscript.sleep 10
i = i - 1
loop
else
shl.sendkeys i
end if
end if
else
count = inputbox("How many times?")
wscript.sleep 2500
do while count > 0
shl.sendkeys spam
wscript.sleep 10
shl.sendkeys "{ENTER}"
wscript.sleep 10
count = count - 1
loop
end if
I'm also going to make a function where you can send multiple lines. Any other ideas?
set shell = createobject ("wscript.shell")
strtext = inputbox ("Write down your message you like to spam")
strtext2 = inputbox ("Message 2")
strtext3 = inputbox ("Message 3")
strtext4 = inputbox ("Message 4")
strtext5 = inputbox ("Message 5")
strtimes = inputbox ("How many times do you like to spam? Type in 1 less than the amount of msgs you want to spam. eg; if want to spam 1000, type 999.Max no.1999")
strspeed = inputbox ("Type 1000 for 1 msg per second 100 for 10 msg per second etc type 1 for fastest")
strtimeneed = inputbox ("How many SECONDS do you need to get to your victims input box? Click where you want to spam.")
If not isnumeric (strtimes & strspeed & strtimeneed) then
msgbox "You entered something else then a number on Times, Speed and/or Time need. shutting down"
wscript.quit
End If
strtimeneed2 = strtimeneed * 1000
do
msgbox "You have " & strtimeneed & " seconds to get to your input area where you are going to spam."
wscript.sleep strtimeneed2
for i=0 to strtimes
shell.sendkeys (strtext & "{enter}")
shell.sendkeys (strtext2 & "{enter}")
shell.sendkeys (strtext3 & "{enter}")
shell.sendkeys (strtext4 & "{enter}")
shell.sendkeys (strtext5 & "{enter}")
wscript.sleep strspeed
Next
wscript.sleep strspeed * strtimes / 10
returnvalue=MsgBox ("Want to spam again?",36)
If returnvalue=6 Then
End If
If returnvalue=7 Then
msgbox "Spambox is shutting down"
wscript.quit
End IF
strtext = inputbox ("Write down your message you like to spam")
strtimes = inputbox ("How many times do you like to spam? Type in 1 less than the amount of msgs you want to spam. eg; if want to spam 1000, type 999")
strspeed = inputbox ("Type 1000 for 1 msg per second 100 for 10 msg per second etc type 1 for fastest")
strtimeneed = inputbox ("How many SECONDS do you need to get to your victims input box? Click where you want to spam")
loop
This is my edit of a code I found online that allows for multiple lines
I think on the countdown you put else if, instead of Elseif, i have also changed some of the indentation to make it easier to read

VBScript to Display Countdown using Vbscript Graphical Elements

I wanted to display a MessageBox which displays countdown from 10 to 1 and autocloses after 10 seconds. As Msgbox in vbscript passes code execution untill the user acts on it i tried it using Popup in Wscript Shell Object
Dim counter
Dim oShell
counter = 10
Set oShell= CreateObject("Wscript.Shell")
While counter > 0
oShell.Popup " Left " & counter & " Seconds",1,"Remind"
counter = counter-1
Wend
But it auto-closes for every second and opens a new popup is there any way i can display the countdown and autoclose using the available GUI elements in vb script
Afraid not, the popup is modal & can't be interacted with while its displayed so there is no way to update its existing content.
If you want a more flexible UI you will need to use something different, the console or HTML in an HTA.
You can use Internet Explorer to create a non-modal display.
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
.navigate("about:blank")
.Document.Title = "Countdown" & string(100, chrb(160))
.resizable=0
.height=200
.width=100
.menubar=0
.toolbar=0
.statusBar=0
.visible=1
End With
' wait for page to load
Do while oIE.Busy
wscript.sleep 500
Loop
' prepare document body
oIE.document.body.innerHTML = "<div id=""countdown"" style=""font: 36pt sans-serif;text-align:center;""></div>"
' display the countdown
for i=10 to 0 step -1
oIE.document.all.countdown.innerText= i
wscript.sleep 1000
next
oIE.quit
I have a code, but it might not help
dTimer=InputBox("Enter timer interval in minutes","Set Timer") 'minutes
do until IsNumeric(dTimer)=True
dTimer=InputBox("Invalid Entry" & vbnewline & vbnewline & _
"Enter timer interval in minutes","Set Timer") 'minutes
loop
flop=InputBox("What do you want to set the timer for?")
if dTimer<>"" then
do
WScript.Sleep dTimer*60*1000 'convert from minutes to milliseconds
Set Sapi = Wscript.CreateObject("SAPI.spVoice")
Sapi.speak "Time's up."
t=MsgBox(flop & vbnewline & vbnewline & "Restart Timer?", _
vbYesNo, "It's been " & dTimer &" minute(s)")
if t=6 then 'if yes
'continue loop
else 'exit loop
exit do
end if
loop
end if
please excuse my weird variable names.
This code is from https://wellsr.com/vba/2015/vbscript/vbscript-timer-with-wscript-sleep/
It actually is possible to edit the countdown, very easily for VBScript, so I don't understand what the problem is.
Here's the code:
Dim counter
Dim oShell
counter =InputBox("")
#if you add =InputBox you can have the choice to type in the amount of times the popup repeats#
Set oShell= CreateObject("Wscript.Shell")
While counter > 0
oShell.Popup " Time until shutdown " & counter & " Seconds",(1),"[3]Critical Viruses Detected
#and if you change the (1) to whatever number you want then you can change how fast the popup repeats and if you join this with the "open command" then you can make a gnarly nondangerous virus#
counter = counter-1
Wend

Resources