Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASendkeys problem 1

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I have a vbscript that launch telnet, login and execute a command in our unix box:

set fs = CreateObject ("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("C:\pwd.txt", 1)
upwd = f.ReadAll

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "telnet unix1"
WScript.Sleep 10000
WshShell.Sendkeys "myusename"
WshShell.Sendkeys "{ENTER}"
WScript.Sleep 10000
WshShell.Sendkeys pwd
WshShell.Sendkeys "{ENTER}
.............................

On some of our users, this script will launch minimized applications such as Excel, word, Lotus notes etc.

Any help will be greatly apprecciated.
 
Actually, what I need is to deactivate all applications when I run telnet.
What is happening was when user run this script (saved on desktop), all minimized applications are activated and the sendkeys is sending the user an password all over the place, whatever was currently active when sendkeys was invoked.
 
Actually, what I need is to deactivate all applications when I run telnet.
What is happening was when user run this script (saved on desktop), all minimized applications are activated and the sendkeys is sending the user an password all over the place, whatever was currently active when sendkeys was invoked.
 
malayqal,
mark's suggestion will "deactivate" all other apps and activate the app you're activating (focusing on). it works.
 
I tried this code below. It worked fine on some computer but on some PC, telnet just flashed and the sendkeys activated the start menu.

set fs = CreateObject ("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("C:\pwd.txt", 1)
pwd = f.ReadAll

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "telnet Unix1"
WshShell.AppActivate "telnet Unix1"
WScript.Sleep 10000
WshShell.Sendkeys "myusename"
WshShell.Sendkeys "{ENTER}"
WScript.Sleep 10000
WshShell.Sendkeys pwd
WshShell.Sendkeys "{ENTER}
 
I revised the code to below and some PC's still can not run it. The telnet session just "flashed" and closed immediately.
I run the telnet session on the cmd prompt and the session "sticks".
The script was working for them before unitl the OS was re-installed.
I was wondering maybe some setting might have changed.


set fs = CreateObject ("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("C:\pwd.txt", 1)
pwd = f.ReadAll

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "telnet Unix1"
WshShell.AppActivate "telnet Unix1"
WScript.Sleep 5000
WshShell.AppActivate "telnet Unix1"
WshShell.Sendkeys "myuser"
WshShell.AppActivate "telnet Unix1"
WshShell.Sendkeys "{ENTER}"
WScript.Sleep 5000
WshShell.AppActivate "telnet Unix1"
WshShell.Sendkeys pwd
WshShell.AppActivate "telnet Unix1"
WshShell.Sendkeys "{ENTER}
 
i have had experience like this with a cmd window. it just flashes and goes away. it's usually when there's an error on the cmd window. or if telnet is not authorized by group policy or something.
 
Replace WshShell.Run "telnet Unix1" with WshShell.Run "CMD.EXE /K telnet Unix1"


That will force open the Command Window and keep it open while your code executes.
You will then need to complete your actions with using sendkey commands to close the window.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
It worked I revised the code as:

set fs = CreateObject ("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("C:\pwd.txt", 1)
pwd = f.ReadAll

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "CMD.EXE /K telnet Unix1"
WshShell.AppActivate "telnet Unix1"
WScript.Sleep 5000
WshShell.AppActivate "telnet Unix1"
WshShell.Sendkeys "myuser"
WshShell.AppActivate "telnet Unix1"
WshShell.Sendkeys "{ENTER}"
WScript.Sleep 5000
WshShell.AppActivate "telnet Unix1"
WshShell.Sendkeys pwd
WshShell.AppActivate "telnet Unix1"
WshShell.Sendkeys "{ENTER}"
WScript.Sleep 5000
WshShell.AppActivate "telnet Unix1"
WshShell.Sendkeys "exit"
WshShell.Sendkeys "{ENTER}"

- After this line, logout and then Connection to host lost and it just hangs
I want to complete the whole process of exiting telnet and cmd.exe altogehter.
I tried adding this to no avail

WshShell.RUN "CMD.EXE /K EXIT"
'WshShell.Sendkeys "exit
 
markdmac, thanks for all the help. Tested it on one of the PC that is having a problem and it is now working fine.
 
Hi,

I am new to this scripting world, i am facing some problem while executing a similar script as described in this thread...

I have to lauch telnet to execute some Unix commands, while searching for the answer, by luck i have seen this tread... and it is quite useful also... but while i am trying to execute the script,

its throwing the message as Object required:'WScript'

Script:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "CMD.EXE /K telnet unix"
WshShell.AppActivate "telnet racerx"
WScript.Sleep 100000
WshShell.AppActivate "telnet unix"
WshShell.Wscript.Sleep 10000
WshShell.Sendkeys username
WshShell.AppActivate "telnet unix"
WshShell.Sendkeys "~"
WshShell.AppActivate "telnet unix"
WScript.Sleep 100000
WshShell.AppActivate "telnet unix"
WshShell.Sendkeys pwd
WshShell.Sendkeys "~"

Thanks in Advance,
Yoga
 
Object required:'WScript'
You code should be in a .VBS file, not an HTML page.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
At Dimac Free Downloads there is a component called w3Sockets that can do both Telnet and "raw" TCP. It was designed for scripting and so uses blocking calls.

It is free though you'll have to register to get it. It also needs to be installed on machines that will run your script. Much more reliable than trying to use SendKeys though, assuming it meets your needs.
 
Anyway, replace this:
WshShell.Wscript.Sleep 10000
with this:
Wscript.Sleep 10000

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top