crenaud76
Messages postés
4172
Date d'inscription
mercredi 30 juillet 2003
Statut
Membre
Dernière intervention
9 juin 2006
28
23 févr. 2005 à 18:26
Oui l efichier doit bine se créer mais le pb c'est que Shell est asynchrone !! Il lance le ping et te rend aussitot la main ! Donc quand VB execute la ligne suivant immédiatement le Shell, le fichier n'a pas encore été créé, car Ping n'a pas fini de s'executer. Va voir mes sources, tu en trouvera une porposant une version synchrone de shell()
Ou alors tu peux utiliser les api pour fair eun ping directement depuis ton code VB
Option Explicit
Const SOCKET_ERROR = 0
Private Type WSAdata
wVersion As Integer
wHighVersion As Integer
szDescription(0 To 255) As Byte
szSystemStatus(0 To 128) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As Long
End Type
Private Type Hostent
h_name As Long
h_aliases As Long
h_addrtype As Integer
h_length As Integer
h_addr_list As Long
End Type
Private Type IP_OPTION_INFORMATION
TTL As Byte
Tos As Byte
Flags As Byte
OptionsSize As Long
OptionsData As String * 128
End Type
Private Type IP_ECHO_REPLY
Address(0 To 3) As Byte
Status As Long
RoundTripTime As Long
DataSize As Integer
Reserved As Integer
data As Long
Options As IP_OPTION_INFORMATION
End Type
Private Declare Function GetHostByName Lib "wsock32.dll" Alias "gethostbyname" (ByVal HostName As String) As Long
Private Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVersionRequired&, lpWSAdata As WSAdata) As Long
Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
Private Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal HANDLE As Long) As Boolean
Private Declare Function IcmpSendEcho Lib "ICMP" (ByVal IcmpHandle As Long, ByVal DestAddress As Long, ByVal RequestData As String, ByVal RequestSize As Integer, RequestOptns As IP_OPTION_INFORMATION, ReplyBuffer As IP_ECHO_REPLY, ByVal ReplySize As Long, ByVal TimeOut As Long) As Boolean
' +-----------------------------------------------------------------------------------------------------------+
' | |
' | Ping(HostName As String) As Boolean |
' | |
' +-----------------------------------------------------------------------------------------------------------+
' | |
' | Objet : |
' | Effectue un 'PING' d'une machine d'après son nom de Host |
' | |
' | Arguments : |
' | HostName -> Nom de la machine à "Pinger" |
' | |
' | Valeur de retour : |
' | True si la machine à répondu et False sinon |
' | |
' | Version : |
' | 1.0 le 04/07/2003 : Première version |
' | |
' +-----------------------------------------------------------------------------------------------------------+
' | Developpement : Christophe RENAUD - CAF Le Havre (763) - DSI |
' +-----------------------------------------------------------------------------------------------------------+
Public Function Ping(HostName As String) As Boolean
Dim hFile As Long, lpWSAdata As WSAdata, hHostent As Hostent, AddrList As Long
Dim Address As Long, OptInfo As IP_OPTION_INFORMATION, EchoReply As IP_ECHO_REPLY
WSAStartup &H101, lpWSAdata
If GetHostByName(HostName + String(64 - Len(HostName), 0)) <> SOCKET_ERROR Then
CopyMemory hHostent.h_name, ByVal GetHostByName(HostName + String(64 - Len(HostName), 0)), Len(hHostent)
CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
CopyMemory Address, ByVal AddrList, 4
End If
hFile = IcmpCreateFile()
If hFile = 0 Then
Ping = False
Exit Function
End If
OptInfo.TTL = 255
IcmpSendEcho hFile, Address, String(32, "A"), 32, OptInfo, EchoReply, Len(EchoReply) + 8, 2000
If EchoReply.Status = 0 Then
Ping = True
Else
Ping = False
End If
IcmpCloseHandle hFile
WSACleanup
End Function
Colle tout ca dans un module standard et appelle la fonction Ping(). Ce ping se fait par le nom de host mais il est possible de la modifier pour faire cela via l'IP
Christophe R