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
| Option Compare Database
Option Explicit
Rem declaration des api qui permettent d'attendre la fin de l'execution avant de passer a autre chose
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Const WAIT_TIMEOUT = &H102&
Function Copy_it(machine_name As String) As String
Dim strmsgbox As String
Dim Démarre, ProcessHandle, retour
Démarre = Shell("C:\" + machine_name + "_batch.bat", vbNormalFocus)
ProcessHandle = OpenProcess(SYNCHRONIZE, False, Démarre)
retour = WaitForSingleObject(ProcessHandle, 1)
Do
retour = WaitForSingleObject(ProcessHandle, 1)
DoEvents
Loop While retour = WAIT_TIMEOUT
retour = CloseHandle(ProcessHandle)
strmsgbox = LireFichier(machine_name)
Copy_it = strmsgbox
Debug.Print Now, machine_name & ": " & Copy_it
End Function
Function LireFichier(machine_name As String) As String
Dim fso As FileSystemObject
Dim fFile As File
Dim ts As TextStream
Dim sPath, result As String
sPath = "\\" & machine_name & "\" & "c$\" & machine_name & "_log.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(sPath) = False Then
Exit Function
End If
Set fFile = fso.GetFile(sPath)
Set ts = fFile.OpenAsTextStream(ForReading)
result = Trim(ts.ReadAll)
ts.Close
Set ts = Nothing
Set fFile = Nothing
Set fso = Nothing
Debug.Print result
LireFichier = result
End Function |
Partager