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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a script to open multiple TELNET connections - XP update 1

Status
Not open for further replies.

gisterennogwel

Technical User
Nov 1, 2007
13
NL
Hi there,

I've been using a script to manage our AccesPoints till this day. But now I've changed to XP and the script fails as XP handles a TELNET connection differently, can anyone pin out the problem in this script?

Code:
'Created for MAC filtering maintenance
'opens a TELNET session to all AP's

filespec="C:\AP.txt"    'data file with IP addresses

dim a,s
s=createobject("scripting.filesystemobject").opentextfile(filespec,1,true).readall
a=split(s,vbcrlf)

set WshShell = CreateObject("WScript.Shell")

for i=0 to ubound(a)
    if trim(a(i))<>"" then
        'Launch telnet session from the command line
        WshShell.Run "telnet " & a(i)
        'Wait until the application has loaded 
	While WshShell.AppActivate("C:\winnt\system32\telnet.exe") = FALSE
	wscript.sleep 100
	Wend
		'Bring the application to the foreground and fill with keys
		WshShell.AppActivate "C:\winnt\system32\telnet.exe"
		wscript.sleep 100
			WshShell.SendKeys "user"
			wscript.sleep 200
			WshShell.SendKeys "{ENTER}"
			wscript.sleep 200
			WshShell.SendKeys "password"
			wscript.sleep 200
			WshShell.SendKeys "{ENTER}"
			wscript.sleep 200
    end if
next

the c:\ap.txt looks like this;
Code:
192.168.25.230
192.168.25.231
192.168.25.245


With W2k the App could be found with the static name C:\winnt\system32\telnet.exe but with XP it’s no longer static as it is named after the connection!
Is there a way to alter this script so I can keep on using it with my new OS?

Thanks for your time.

Ronald.


 
Yes, ideally instead of hard coding the windows directory you should detect where it is since it can be different on an upgrade versus new install.

Code:
'Created for MAC filtering maintenance
'opens a TELNET session to all AP's

filespec="C:\AP.txt"    'data file with IP addresses

dim objFSO, a, s, WshShell, Windir, i
Set objFSO = CreateObject("Scripting.FileSystemObject")

s = objFSO.opentextfile(filespec,1,true).ReadAll
a = Split(s,vbCrLf)

Set WshShell = CreateObject("WScript.Shell")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

For i=0 to UBound(a)
    If Trim(a(i))<>"" Then
        'Launch telnet session from the command line
        WshShell.Run "telnet " & a(i)
        'Wait until the application has loaded 
    While WshShell.AppActivate("C:\" & WinDir & "\system32\telnet.exe") = FALSE
    wscript.sleep 100
    Wend
        'Bring the application to the foreground and fill with keys
        WshShell.AppActivate "C:\" & WinDir & "\system32\telnet.exe"
        wscript.sleep 100
            WshShell.SendKeys "user"
            wscript.sleep 200
            WshShell.SendKeys "{ENTER}"
            wscript.sleep 200
            WshShell.SendKeys "password"
            wscript.sleep 200
            WshShell.SendKeys "{ENTER}"
            wscript.sleep 200
    End If
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 

markdmac,

You missed the problem; I guess I'm not so good in describing the issue.

The path to Telnet is not the issue; Telnet is situated in a directory covered by %path%.

The problem lies in the name of the active application. Under W2K every Telnet session was named C:\winnt\system32\telnet.exe if you would look it up in taskmgr.
In XP it is named Telnet 192.168.25.230 for the first address in AP.txt
Hence, I cannot bring the app to the foreground to send the login keys.

Any suggestions?

Regards,

Ronald.
 
OK, so enumerate through all processes with WMI and look for Left(Process.Name,6)="Telnet"

So something like

For each Process in ColProcesses
If Left(Process.Name,6)="Telnet" Then
WshShell.AppActivate Process.Name
End If
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 

markdmac

You are seriously overestimating my knowledge; I have absolutely no clue as how to use WMI or VBS.
I got this script with help from this forum and I can kind of read what it is doing, but editing is a whole different ballgame.

Thanks for your input so far but I ‘m not possible to integrate you latest suggestions in my script

®
 
Give this a whirl

Code:
'Created for MAC filtering maintenance
'opens a TELNET session to all AP's
On Error Resume Next
strComputer = "."
filespec="C:\AP.txt"    'data file with IP addresses

Dim objFSO, a, s, WshShell, Windir, i, objWMIService

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

s = objFSO.opentextfile(filespec,1,true).ReadAll
a = Split(s,vbCrLf)

Set WshShell = CreateObject("WScript.Shell")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

For i=0 to UBound(a)
    If Trim(a(i))<>"" Then
        'Launch telnet session from the command line
        WshShell.Run "telnet " & a(i)
        'Wait until the application has loaded
    	WScript.Sleep 300    
		Set ColProcesses = objWMIService.ExecQuery("Select * from Win32_Process",,48)
		For Each Process in ColProcesses
		   If Process.Name = "Telnet " & a(i) Then
		      WshShell.AppActivate Process.Name
		   End If
		Next
            wscript.sleep 100
            WshShell.SendKeys "user"
            wscript.sleep 200
            WshShell.SendKeys "{ENTER}"
            wscript.sleep 200
            WshShell.SendKeys "password"
            wscript.sleep 200
            WshShell.SendKeys "{ENTER}"
            wscript.sleep 200
    End If
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top