2

I'm new to VBS, just trying to figure out how I can run a script which prompts the user for input, & then types that result as part of a sentence?

I'm using WshShell.SendKeys as I want the script to be flexible & able to enter the text into different programs, would there be a way to have this type something that was entered into an InputBox?

Thanks!

0

2 Answers 2

2

This is a very simple example of how to get InputBox to take your input, then send the keys to a command prompt. I think you can work out how to adapt this for any other program pretty easily.

Option Explicit

Dim a
a = InputBox("Enter your name", "Example")

Dim sh
Set sh = WScript.CreateObject("WScript.Shell")
sh.Run "cmd"
WScript.Sleep 200 
sh.AppActivate "C:\Windows\system32\cmd.exe" 
WScript.Sleep 200 
sh.SendKeys "echo Hello " & a & "!"
sh.SendKeys "{ENTER}"

When you run this and enter the word "CrowStorm", CMD will open and echo the sentence "Hello CrowStorm!"

Sign up to request clarification or add additional context in comments.

Comments

0

This would work if you were trying to put this into notepad:

Option Explicit
    Dim WshShell,input
    Set WshShell =CreateObject("WScript.Shell")
    input = InputBox("Enter your name", "Example")
    WshShell.Run("notepad")
    WScript.Sleep 200 
    Wshshell.SendKeys "Hello " & input & "!"
    WshShell.SendKeys "{ENTER}"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.