ajtsystems
IS-IT--Management
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 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