ganesh_6663
New Member
- Joined
- Jul 15, 2021
- Messages
- 33
- Office Version
- 2016
- Platform
- Windows
Need to open putty from "C:/D:/E:/F:" any of the given drive , without chaging path inside macro every time.
VBA Code:
Option Explicit
Public Sub test()
Dim PuttyPID As Double
#If VBA7 Then
Dim PuttyHwnd As LongPtr
#Else
Dim PuttyHwnd As Long
#End If
Dim serverName As String, username As String, password As String
serverName = "xxx.yyy"
username = "xxxx"
password = "xxxx"
PuttyPID = Shell("C:\Program Files\PuTTY\putty.exe -telnet " & serverName, vbNormalFocus) 'CHANGE PATH TO .EXE
'Get window handle of the PuTTY Telnet command window
PuttyHwnd = GetWindowHandle(CLng(PuttyPID))
If PuttyHwnd <> 0 Then
SendChars PuttyHwnd, username & vbCr
Application.Wait DateAdd("s", 1, Now)
SendChars PuttyHwnd, password & vbCr
Application.Wait DateAdd("s", 1, Now)
SendChars PuttyHwnd, "DIR" & vbCr 'DIR command
End If