Insert a user variable to wshshell for a Telnet script - vbscript

I am trying to find how to make the Telnet IP address a variable that the user supplies. The script works fine as it is but there many host addresses that I have to run this script on. As it is I have to edit the file with the new IP address each time I use it. The full script has many Sendkeys entries that I have removed.
job>
script language="VBScript">
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
WshShell.SendKeys "telnet 160.221.230.127"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "user XXX XXX"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "cci resetapb cancel"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WScript.Quit
</script>
</job>

You can prompt for input using InputBox
dim res: res = InputBox("enter ip address", "?", "192.168.1.1")
msgbox res
Parameters are:
prompt
dialog title
default

Use this example
Set WshShell = CreateObject("WScript.Shell")
ServerIP = InputBox ("Enter IP")
WshShell.Run ("telnet " & ServerIP)
WScript.Sleep(500)
WshShell.SendKeys("login~")
WScript.Sleep 100
WshShell.SendKeys("password~")
WScript.Sleep 100

Related

run as administrator password contain tilde

How can I use special character password like mine have Tilde in my password as Ka$$1001~1
Here is the script below, I'm unable to run the script.
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run "runas /user:administrator92 " & chr(34) & a & chr(34)
WScript.Sleep 1000
WshShell.SendKeys "Ka$$1001~1" 'send password
WshShell.SendKeys "{ENTER}"
As documented, ~ is the shorthand for {Enter} (the Enter key). Put special characters in curly braces:
{+} {^} {%} {~} {(} {)} {[} {]} {{} {}}
So your line will be as following:
WshShell.SendKeys "Ka$$1001{~}1" 'send password

Need to change DSRM password on multiple W2K3 DC's (Automatically) without entering password manually

ntdsutil "set dsrm password" "reset password on server %1" "newpassword" "newpassword" q q
I have tried but still it is asking password manually please provide me some script to enter password automatically when it prompts.
Set WshShell = WScript.CreateObject("WScript.Shell"):
WshShell.Run "cmd", 9:
WScript.Sleep 500:
WshShell.SendKeys " ntdsutil ":
WshShell.SendKeys "{ENTER}":
WshShell.SendKeys "{set dsrm password}":
WshShell.SendKeys "{ENTER}":
WshShell.SendKeys "{sync from domain account Admin}":
WshShell.SendKeys "{ENTER}":
WshShell.SendKeys "Hello World!":
WshShell.SendKeys "{ENTER}":
WScript.Sleep(2000):
WshShell.SendKeys "Hello World!":
WshShell.SendKeys "{ENTER}":

VBS with space in file path 3

I have a VBS but the path to a file has a space as below, I have tried putting it inbetween "" but it gives an error, please help.
Set Objshell=wscript.Createobject("Wscript.Shell")
Objshell.Run "Telnet"
wscript.sleep 100
Strday= left(date,2)
Strmonth = right(left(date,5),2)
StrYear = Right(date,4)
StrHr = Left(Time,2)
StrMin = Right(Left(time,5),2)
StrSec = Right(Time,2)
StrDate=Stryear & StrMonth & StrDay &"_"& StrHr & StrMin & StrSec
Wscript.sleep 1000
Objshell.sendkeys "set Logfile ""L:\09 Phones\Switch_Logs\""" & StrDate & ".txt"
Objshell.sendkeys "~"
Wscript.sleep 1000
Its the
Objshell.sendkeys "set Logfile ""L:\09 Phones\Switch_Logs\""" & StrDate & ".txt"
bit that im having the problem with.
clear text : set Logfile "L:\09 Phones\Switch_Logs\xxxxxxxxxxxx.txt"
double quotes : set Logfile ""L:\09 Phones\Switch_Logs\xxxxxxxxxxxx.txt""
quote as string : "set Logfile ""L:\09 Phones\Switch_Logs\xxxxxxxxxxxx.txt"""
cut for variable: "set Logfile ""L:\09 Phones\Switch_Logs\" ".txt"""
concatenate : "set Logfile ""L:\09 Phones\Switch_Logs\"& StrDate &".txt"""
Result
objShell.sendKeys "set Logfile ""L:\09 Phones\Switch_Logs\"& StrDate &".txt"""

VBs to log (.txt) telnet output

A very simple script to save time for something i (repeatedly) need to check # work;
Set cloner = CreateObject("WScript.Shell")
cloner.SendKeys"telnet 0.0.0.0"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000
cloner.SendKeys("whatever")
And, i'd like this to output to a .txt.
try this one
Set cloner = CreateObject("WScript.Shell")
cloner.Run "cmd.exe"
WScript.Sleep 1000
cloner.SendKeys"telnet 0.0.0.0 -f out.txt"
cloner.SendKeys("{Enter}")
WScript.Sleep 1000
cloner.SendKeys("whatever")
The code just producing a blank txt; no string in it.
Try:
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run("telnet.exe")
WScript.Sleep 500
WshShell.SendKeys("set logfile filename.txt{Enter}")
WScript.Sleep 500
WshShell.SendKeys("open 0.0.0.0{Enter}")
WScript.Sleep 500
WshShell.SendKeys("whatever")
this will create a file named filename in the working directory, can be replaced with absolute path aswell.

How to send Alt+space to console window?

import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("Command Prompt")
shell.SendKeys("%{ }") # This
#shell.SendKeys("% ") # and this
#shell.SendKeys("%( )") # and this is not working
WScript is not mandatory, you can propose any programmatic solution.
Scan codes (56 and 57) are required:
from win32api import *
from win32con import *
keybd_event(VK_LMENU, 56, 0, 0)
keybd_event(VK_SPACE, 57, 0, 0)
keybd_event(VK_SPACE, 57, KEYEVENTF_KEYUP, 0)
keybd_event(VK_LMENU, 56, KEYEVENTF_KEYUP, 0)
I think it is a bug in windows. Here is an example where in notepad the "% " works and in CMD it does not:
' SendKeys.vbs Example Script
' VBScript to send keyboard strokes to command prompt and notepad
' --------------------------------------------------------'
Option Explicit
Dim objShell, WshShell
set objShell = CreateObject("WScript.Shell")
objShell.Run("cmd")
objShell.AppActivate("Command Prompt")
WScript.Sleep 500
objShell.SendKeys "notepad~"
WScript.Sleep 500
' It works
objShell.SendKeys "% x"
WScript.Sleep 200
objShell.SendKeys "% r"
WScript.Sleep 200
objShell.SendKeys "%v"
WScript.Sleep 200
objShell.SendKeys "s"
WScript.Sleep 200
objShell.SendKeys "Algo{Enter}"
WScript.Sleep 500
objShell.SendKeys "%{TAB}"
WScript.Sleep 500
objShell.SendKeys "dir~"
WScript.Sleep 500
'Does not work
objShell.SendKeys "% es"
WScript.Sleep 3500
objShell.SendKeys "{BACKSPACE}{BACKSPACE}Exit~"
WScript.Sleep 3500
objShell.SendKeys "%fx"
WScript.Sleep 500
objShell.SendKeys "{TAB}~"
WScript.Quit
' End of SendKeys Example Script

Resources