ganesh_6663
New Member
- Joined
- Jul 15, 2021
- Messages
- 33
- Office Version
- 2016
- Platform
- Windows
Created tool to auto putty login into jumpserver first , from Jumpserver it will login into mainserver .
But some time mainserver is not reachable still script send username and password ......is their any way to stop sending username and password if mainserver not reachable ..
But some time mainserver is not reachable still script send username and password ......is their any way to stop sending username and password if mainserver not reachable ..
VBA Code:
Sub PUTTYSM()
Dim PuttyPID As Double
Dim PuttyHwnd As LongPtr
Dim serverName As String
Dim username As String
Dim password As String
Dim Jumpserver As Variant
Dim myserver As Variant
myserver = UserForm1.Reg2.Value
Jumpserver = UserForm1.Reg3.Value
username = "demo"
password = "password"
mainserverpass = "password"
'Login jump server
PuttyPID = Shell("D:\putty.exe -ssh " & Jumpserver, vbNormalFocus) 'CHANGE PATH TO .EXE
PuttyHwnd = GetWindowHandle(CLng(PuttyPID))
If PuttyHwnd <> 0 Then
Application.Wait DateAdd("s", 2, Now)
SendChars PuttyHwnd, username & vbCr
Application.Wait DateAdd("s", 2, Now)
SendChars PuttyHwnd, password & vbCr
[B]'Login main server
Application.Wait DateAdd("s", 1, Now)
SendChars PuttyHwnd, "ssh demo@" & myserver & vbCr
Application.Wait DateAdd("s", 1, Now)
SendChars PuttyHwnd, mainserverpass & vbCr[/B]
End If
End Sub