Merci AlainTech, l'habitude de devoir tout écrire en anglais dans mon travail.
ci aprés mon post reformulé en Français.

J'ai besoin d'aide concernant un prb d'interaction avec putty sur excel vba. D'abord, ce que je cherche à faire c'est à partir d'une liste d'adresse
IP j'ai besoin de faire 2 tests. Le premier test est la connection sur le système et le second test que le login password référencé est correct.
Pour celà j'ai trouvé de approche différente mais qui ne me donne pas à 100% ce dont j'ai besoin.

Dans ma première option, j'utilise le Wscript.shell avec une implémentation errorcode. Cette solution me permet effectivement de faire ma connection
ainsi que l'authentification en utilisant le argument de défaut de plink ou putty. Par contre une fois authentifier, je ne peux pas faire de sendkeys
de type enter ou exit ce qui empêche mon script de continuer sans une intervention manuel de ma part afin de faire un exit pour fermer la connection et ma fenêtre.
Ci aprés le code que j'utilise réaliser avec l'aide de plusieurs tip trouvé dans les forums.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
Sub Button1_Click()
    Dim wSheet As Worksheet
    Dim wsh As Object
    Set wsh = VBA.CreateObject("WScript.shell")
    'Dim waitOnReturn As Boolean: waitOnReturn = True
    Dim waitOnReturn As Boolean: waitOnReturn = Wait
    Dim WindowStyle As Integer: WindowStyle = 1
    Dim errorCode As Long
    Dim fname As Variant
    Dim FileFormatValue As Long
    Dim login As String
    Dim password As String
    Dim protect As String
    Dim IPAdd As String
    Dim rng As Range, cell As Range
 
    Set rng = Range("B2:B7")
    For Each cell In rng
        IPAdd = cell.Value
        errorCode = wsh.Run("plink " & IPAdd & " -P 22 -l admin -pw Password", WindowStyle, waitOnReturn)
        If errorCode = 0 Then
           MsgBox "Connection to Device Done!"
        Else
           MsgBox "Connection to VSM Sharepoint Failed"
        End If
    Next cell
 
End Sub
Ma deuxième solution aussi trouvé dans un forum, elle me permet de faire ce dont j'ai besoin, mais mon problème
là est que le code gère toute les ip en simultanée sans attendre la fermeture de la connection. mes sendkeys fonctionne correctement.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
Option Explicit
 
Public Const WM_CLOSE = &H10
Public Const INFINITE = -1&
Public Const SYNCHRONIZE = &H100000
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
 
 
 
#If VBA7 Then
    Declare PtrSafe Function lbf_ShellExecute Lib "shell32" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Declare PtrSafe Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
    Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Declare PtrSafe Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
    Declare PtrSafe Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
 
#Else
    Declare Function lbf_ShellExecute Lib "shell32" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Public Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
    Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
#End If
 
Function TerminateTunnel()
 
Dim lngHandle As Long
Dim lngResult As Long
 
lngHandle = OpenProcess(SYNCHRONIZE Or STANDARD_RIGHTS_REQUIRED Or &HFFF, False, GetWindowHandle("Plink.EXE"))
lngResult = TerminateProcess(lngHandle, 0)
lngResult = CloseHandle(lngHandle)
 
End Function
Function GetWindowHandle(strWindowName As String) As Long
Dim w As Object
Dim sQuery As String
Dim objAllProcesses As Object
Dim objProcess As Object
 
    Set w = GetObject("winmgmts:")
    sQuery = "SELECT * FROM win32_process"
    Set objAllProcesses = w.execquery(sQuery)
 
    For Each objProcess In objAllProcesses
        If objProcess.Name = strWindowName Then
            'Once you get the handle, you cannow exit to function and return the handle
            GetWindowHandle = objProcess.Handle
            'Debug.Print process.Name, process.Handle, process.Caption
            GoTo EXitThisFunction
        End If
    Next
 
EXitThisFunction:
 
    On Error Resume Next
    Set w = Nothing
    Set objAllProcesses = Nothing
    Set objProcess = Nothing
 
End Function
 
 
Function CreateSSHTunnelUsingPutty()
 
Dim strFilename As String, strCommandLine As String
Dim strCurrPath As String
Dim lngWindowHandle As Long
Dim strServerPOrt As Long
Dim strServerUser As String
Dim strServerPassword As String
Dim IPAdd As String
Dim rng As Range, cell As Range
 
strServerPOrt = 22 'Sample POrt
strServerUser = "admin" 'Sample User Name
strServerPassword = "Password"  'Sample Password
 
'Set rng = Range("B2:B7")
For Each cell In ActiveSheet.Range("B2:B7")
IPAdd = cell.Value
'strCurrPath = CurrentProject.Path & "\"
strFilename = "Plink.exe"
strCommandLine = IPAdd & " -P " & strServerPOrt & " -l " & strServerUser & " -pw " & strServerPassword
 
'The command line will look something like this
'  "Server_IP_address -P 22 -l root -pw MyPassword"
 
'Debug.Print strFilename
'Debug.Print strCommandLine
 
'Launch tunnel
Call lbf_ShellExecute(0, "open", strFilename, strCommandLine, "", 1)
'Change the last parameter from a one to a zero and the
'connection window will be hidden.
 
Sleep (1000)
'SetForegroundWindow (GetWindowHandle("Plink.EXE"))
 
'Send a 'n' (no) which means trusted certificate is not stored on users PC)
SendKeys "n + {ENTER}", True
SendKeys "{ENTER}", True
SendKeys "{ENTER}", True
SendKeys "{ENTER}", True
SendKeys "exit", True
SendKeys "{ENTER}", True
SendKeys "{ENTER}", True
 
'Tunnel is now created
Next cell
 
End Function
Ce dont j'ai besoin, c'est de gérer mes connections les unes aprés les unes comme me le permet la 1ere solution,
mais sans avoir à intervenir manuellement pour fermer la fenêtre putty aprés avoir valider que ma connection est ok
ainsi que le login password.
Si quelqu'un à une solution par exemple basé sur ma 2eme option afin de gérer une loop qui traite mes adresses IP une par une
ce serait nickel.
Par avance merci de votre aide
Cordialement
Thibaut