Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

SendKeys vbscript method only targets active window

$
0
0

Hail to the gurus... 

I've an issue here.  We're running a script that pulls IP addresses from a file, opens a telnet session to each in turn, and then requests some data from the host before exiting and going to the next session.  

AUTO-TELNET.CMD

FOR /F "TOKENS=1" %%A IN (IP.TXT) DO (
   ECHO Telnet to %%A in progress...
   START /MIN SENDKEYS.VBS
   START /WAIT CMD /C TELNET -F %%A.TXT %%A
   ECHO Telnet to %%A complete. 

   ECHO Filtering data... 

REM Filtering criteria would go here 

   ECHO Data filter for %%A complete.
   )
ECHO Job Complete. Exiting now. 
SENDKEYS.VBS
set objshell = wscript.createobject("wscript.shell")

wscript.sleep (12000)

objshell.sendkeys "{enter}"
objshell.sendkeys "system info"
objshell.sendkeys "{enter}"

wscript.sleep(6000)

objshell.sendkeys "quit"
objshell.sendkeys "{enter}"

wscript.sleep(2000)

objshell.sendkeys "{enter}"

The problem is, we're using SendKeys in a VBS script to actually send the commands to Telnet.  The problem arises in that SendKeys basically commandeers the keyboard, and has no real way of ensuring that a specific window receives the keystrokes.  As a result, even when we launch this script in a VM, it has a habit of 'wigging out' and sending keystrokes to the wrong window.  This potentially pollutes the data being gathered, if you so much as select the file, the next Enter that SendKeys spits out will open that file and then all subsequent commands get injected into the data.

Looking to 'upgrade' this to PowerShell, but while we do that, is there any way we can specifically target a window to send keys to? Perhaps adjust sendkeys.vbs to accept an argument for the IP address, and then ensure that right before sending anything, that the window with that IP is Active (and if none exists, to skip sending any keys and just jump to the end?)

Thanks! :)


Viewing all articles
Browse latest Browse all 2562

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>