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
Related
I have a Windows service which calls a bat file. That bat file calls a PowerShell script, and inside that PowerShell script a VBScript is called.
Windows Service > bat file > powershell file > vbscript
When I manually run the bat file, the VBscript is successfully executed, but if I execute the same bat file from the Windows service, then all scripts are called, but the VBScript skips to run.
Executing a bat file manually successfully executes the VBScript, but not via Windows service
I tried to call The VBScript inside PowerShell in different ways:
& c:\windows\system32\cscript.exe NameOfFile.vbs
start-process
invoke-expression
C:\Windows\System32\cscript.exe NameOfFiles.vbs //B //Nologo $IP_SU $RemoteSessions_Output $user
My VBScript is:
dim ip
dim sessions_dir
dim temp
dim username
dim password
set temp = Wscript.Arguments
ip = temp(0)
sessions_dir = temp(1)
username = temp(2)
password = temp(3)
Sub WaitEnter()
WshShell.AppActivate("telnet " & ip )
WScript.Sleep 2000
WshShell.AppActivate("telnet " & ip)
WshShell.SendKeys "{Enter}"
WshShell.AppActivate("telnet " & ip)
WScript.Sleep 2000
End Sub
set WshShell = WScript.CreateObject("WScript.Shell")
Wscript.Sleep 1000
WshShell.AppActivate("telnet " & ip )
WshShell.Run "telnet " & ip & " -f " & sessions_dir & "\" & ip & "_SU_Status_Output.txt",2
WshShell.AppActivate("telnet " & ip)
WScript.Sleep 1000
WshShell.AppActivate("telnet " & ip)
WshShell.SendKeys username
WaitEnter
WshShell.AppActivate("telnet " & ip)
WshShell.SendKeys password
WaitEnter
WshShell.AppActivate("telnet " & ip)
WshShell.SendKeys "SU_INrOmk=` pl | awk '{{}print {$}3{}}' | head -3 | cut -d '=' -f2`; SU_type=` pl | grep $SU_INrOmk | tail -1 | awk '{{}print {$}12{}}'`"
WaitEnter
WshShell.AppActivate("telnet " & ip)
WshShell.SendKeys "echo $SU_type"
WaitEnter
WshShell.AppActivate("telnet " & ip)
WshShell.SendKeys "exit"
WshShell.AppActivate("telnet " & ip)
WshShell.SendKeys "{Enter}"
and PowerShell script from where it is called is like:
if(Test-Path C:\Windows\System32\cscript.exe){
echo "Cscript found"
$command = "& C:\Windows\System32\cscript.exe NameOfFile.vbs $IP_SU $RemoteSessions_Output $user $DecPwd | out-null"
Invoke-Expression -Command $Command
start-Sleep 10
if($?){
start-sleep 10
$SU_Output_File = $IP_SU + "_SU_Status_Output.txt"
$SU_Remote_FilePath = $RemoteSessions_Output + "\" + $SU_Output_File
}
}
i expect that VBScript is called when Windows service calls the bat file.
I see several things that could be causing issues for you here.
I'm no master of VBS, but my guess here is that you are using Wscript which requires interactivity I think, but you should be using Cscript variant calls instead. My guess is that your script may be bombing due to this. Services can not run in an interactive context since Vista/Windows Server 2008.
You are calling this with Invoke-Expression, which (almost) always returns successful even if the cmdlet failed. In other words, Invoke-Expression will (almost) always set $? to $True even if the command failed. However, you can slip in an evaluation of ; $? at the end of your expression which will end up setting $? as you would expect, which breaks the notion of "always sets $? to $True".
However, you are also using $? incorrectly as well. $? only evaluates the success of cmdlets, not commands. cscript.exe is an executable, and must have its success evaluated with the $LASTEXITCODE automatic variable instead. This will be typically be 0 for success and any other value for non-success. You will have to check the success of this $LASTEXITCODE yourself, as even when the ErrorActionPreference is set to Stop, it won't automatically treat non-zero exit codes as terminating errors.
Outside of the scope of this answer, but worth a mention, I would recommend replacing Invoke-Expression with a straight call to the executable and splat your parameters instead.
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
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}":
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"""
I created the following runas.vbs script:
**************
Option explicit
Dim oShell, k
Const PASSWORD = "Pass123~"
set oShell= Wscript.CreateObject("WScript.Shell")
WScript.Sleep 500
oShell.run("RunAs /noprofile /user:%computername%\postgres " & Chr(34) & "cmd /c\" &
Chr(34) & WScript.Arguments(0) & "\" & Chr(34) & Chr(34))
WScript.Sleep 1000
For k=1 To Len(PASSWORD)
WScript.Sleep 200
oShell.SendKeys Mid(PASSWORD,k,1)
Next
Wscript.Quit
**************
I use this vbscript in a Batch file to run initdb.exe (Postgresql).
Used as:
cscript //Nologo //B runasNSPostgres.vbs ""%LG_PATH%\initdb.exe" --locale=C --encoding=UTF-8 -U %DBADMIN% -D "%DBDATA%""
When this command is executed, another command prompt screen opens up which starts the initdb processing. I do not want the new cmd prompt screen to show up. I want the initdb.exe to run in the background.
If you hide the command prompt window, you won't be able to use SendKeys to send it your password keystrokes.
You can use another method, though. Try using the ECHO command and pipe its output to RunAs.
oShell.Run "echo " & PASSWORD & " | runas /noprofile ...", 0
Use a 0 as the 2nd parameter to prevent the window from appearing.