Single Line Input VBS Autotyper - vbscript

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

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.

Turn off a VBScript program while it is running

(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.

How can I end a Do Loop after some sort of user input?

Any kind of user input will do. Here's the code I have so far.
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim Account
Account = 111111
WScript.Sleep 5000
Do
WScript.Sleep 400
WshShell.SendKeys "drill "
WshShell.SendKeys Account
WshShell.SendKeys "{ENTER}"
Account = Account + 1
Loop
Basically it's a code guesser (for a game) and I want to be able to interrupt it with any kind of user input.
I don't think we have any direct solution. Below code seeks for user interaction after 50 iterations. If yes, control exits from do loop. You can play around with other ways to interrupt the loop and of course you can change the counter as per your need.
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim counter
Dim Account
Dim msgResult
counter = 0
Account = 111111
WScript.Sleep 5000
Do
WScript.Sleep 400
WshShell.SendKeys "drill "
WshShell.SendKeys "drill "
WshShell.SendKeys Account
WshShell.SendKeys "{ENTER}"
Account = Account + 1
If counter = 50 Then 'get user input after 50 iterations
msgResult = MsgBox("Do you want to exit?", vbYesNo)
If msgResult = vbYes Then 'if yes
Exit Do
End If
End If
counter = counter + 1
If counter > 101 then
counter =0
End If
Loop

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

Scripting MMC with vbscript

I would like to add a snap in via vbscript and I have been having a problem getting the snap in to add to the console. It will be run in a Windows 7 environment. If someone could have a look see and direct me in the right direction I would be most grateful. Thanks.
<code>
'Elevated privileges start
'Start of UAC workaround code
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If WScript.Arguments.length =0 Then
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "wscript.exe", Chr(34) & _
WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
consoleName = "C:\Burnett.msc"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(consoleName) Then
Wscript.Echo "console already exists"
Else
On Error Resume Next
Set objMMC = CreateObject("MMC20.Application")
If err.Number <> 0 Then
Wscript.Echo "an error occurred. unable to create mmc console"
Wscript.Quit(0)
End If
objMMC.Show
Set objDoc = objMMC.Document
objDoc.snapins.add("Local Computer\Non-Administrators")
if err then
'Trap the error just after the statement where an error/exception can occur and handle it elegantly
msgbox("Snap-in Not found")
err.clear
end if
objDoc.ActiveView.StatusBarText = "Pane 1|Pane 2|Pane 3"
objMMC.UserControl = 1
objDoc.Name = consoleName
objDoc.Save()
End If
Set fso = Nothing
End If
</code>
"Local Computer\Non-Administrators" is just a system-supplied description for the particular configuration of a snap-in. In this case, the actual snap-in name is "Group Policy Object Editor". Thus to eliminate the error in the code change
objDoc.snapins.add("Local Computer\Non-Administrators")
to
objDoc.snapins.add("Group Policy Object Editor")
Unfortunately, this will only get you as far as MMC putting up a "Select Group Policy Object" dialog. You will then have to manually select the configuration you need using that dialog. As far as I can tell there is no way to supply Snapins.Add with the parameters to select the local non-admin users.
The code below will fully automate the process of setting up the snap-in. However, its reliance on SendKeys makes it extremely brittle. It worked on my system, but there's a good chance you'll need to modify the sequence of key strokes and/or the timing delays to make it work on your system. And once you get it working, there's no guarantee it will continue to do so as local conditions are mutable and can greatly effect the timing.
option explicit
if WScript.Arguments.Named.Exists("elevated") = false then
'Launch the script again with UAC permissions
CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1
WScript.Quit
end if
Dim mmc : set mmc = WScript.CreateObject("MMC20.Application")
mmc.Show
mmc.UserControl = 1 'to keep MMC open
Dim oShell : set oShell = WScript.CreateObject("Wscript.Shell")
oShell.AppActivate "Console1"
WScript.Sleep 200
oShell.SendKeys "%f"
WScript.Sleep 200
oShell.SendKeys "m"
WScript.Sleep 400
oShell.SendKeys "group{TAB}{ENTER}"
WScript.Sleep 1000
oShell.SendKeys "{TAB}{ENTER}"
WScript.Sleep 1000
oShell.SendKeys "{TAB}{TAB}{TAB}{RIGHT}{TAB}Non{ENTER}"
WScript.Sleep 1000
oShell.SendKeys "{TAB}{TAB}{ENTER}"
WScript.Sleep 1000
oShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{ENTER}"

Resources