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!

Telnet and Enter commandes

Status
Not open for further replies.

ajtsystems

IS-IT--Management
Jan 15, 2009
80
GB
Hi,

I am writing a script to allow use3s to reboot their own linux machines via Terminal server RemoteApps. I don't want to give them any more access via Telnet than they need, so would like to script the restart process via command line.

So far the user enters the IPAddress and my script check the network connectivity via WMI then attempts to telnet in and run some commands.

I have some security concerns about the wshshell.SendKeys function as brighter users could "Ctrl" and get access to the command prompt.

I have looked at the wscript.run command as this allows silent running of the cmd prompt but its not working.

Does anyone know a method for doing this silently, with still being able to enter multiple lines in telnet without user interaction? Here is my code so far:



IPAddress = inputbox( "Please Enter IP Address:" )
Username = inputbox( "username:" )
password = inputbox( "password:" )


Set wshshell = WScript.CreateObject("WScript.Shell")


'==========================================================================
' The following function will test if a machine is reachable via a ping
' using WMI and the Win32_PingStatus
'==========================================================================
If Reachable(IPAddress) Then
'WScript.Echo "Computer is Reachable"
'Else
'WScript.Echo "Computer is Unreachable!"
End If

Function Reachable(strComputer)
' On Error Resume Next

Dim wmiQuery, objWMIService, objPing, objStatus

wmiQuery = "Select * From Win32_PingStatus Where " & _
"Address = '" & strComputer & "'"

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)

For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
Reachable = False 'if computer is unreacable, return false
Else
Reachable = True 'if computer is reachable, return true
End If
Next


if reachable = true then
call Telnet
Else wscript.echo "IP Address not reachble"
wscript.echo "Contact TSS"
wscript.quit
end if
End Function


Sub Telnet
'Start up command prompt
'wshshell.run"cmd.exe"
WScript.Sleep 500
'Send keys to active window
'wshshell.SendKeys"telnet " & IPAddress & " 21"
wshShell.run "telnet " & IPAddress & " 21",0,True
WScript.Sleep 1000

'write the username to the cmd window

wshshell.SendKeys("{Enter}")
WScript.Sleep 500
wshshell.SendKeys username
wshshell.SendKeys("{Enter}")


end sub

 
I don't know anything about Linux and WMI on it, but Windows has Win32_OperatingSystem which supports a reboot method. Perhaps you can investigate if Linux has that too.

I hope that helps.

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