/ Forside / Teknologi / Udvikling / VB/Basic / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
VB/Basic
#NavnPoint
berpox 2425
pete 1435
CADmageren 1251
gibson 1230
Phylock 887
gandalf 836
AntonV 790
strarup 750
Benjamin... 700
10  tom.kise 610
Kald af bat-fil - ny proces?
Fra : M!


Dato : 12-12-02 11:05


Hej,

Jeg har en bat-fil som jeg gerne vil kalde fra VBA.

Mit mål er at kalde bat-filen, vente til denne er færdig hvorefter jeg
kan teste på returkoden fra denne.

Hvordan er det liiiiige man gør det?!?


På forhånd tak!

M!

 
 
///JJ (12-12-2002)
Kommentar
Fra : ///JJ


Dato : 12-12-02 16:51

"M!" <morten.vinther@sol.dk> wrote in message
news:3df85e63.12652693@news.tele.dk...
>
> Hej,
>
> Jeg har en bat-fil som jeg gerne vil kalde fra VBA.
>
> Mit mål er at kalde bat-filen, vente til denne er færdig hvorefter jeg
> kan teste på returkoden fra denne.
>
> Hvordan er det liiiiige man gør det?!?

Sådan her:


Funktionkald:
Result = Shell(tmpFile, vbMinimizedNoFocus))
ExitCode = WaitForProcess(Result)
If ExitCode Then
'Der er sket en fejl
End If


Tilhørende Sub:

Attribute VB_Name = "modWait"
Option Explicit

Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As
Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As
Long, lpExitCode As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
As Long
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As
Long, ByVal dwMilliseconds As Long) As Long

Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Const INFINITE = &HFFFF
Private Const WAIT_FAILED& = -1&
Private Const STILL_ACTIVE = &H103
'

Function WaitForProcess(ByVal idProc As Long, Optional ByVal Sleep As
Boolean) As Long
Dim iExitCode As Long, hProc As Long

' Get process handle
hProc = OpenProcess(PROCESS_ALL_ACCESS, False, idProc)

If Sleep Then
' Sleep until process finishes
Dim iResult As Long
iResult = WaitForSingleObject(hProc, INFINITE)
If iResult = WAIT_FAILED Then Err.Raise Err.LastDllError

' Save the return code
GetExitCodeProcess hProc, iExitCode
Else
' Get the return code
GetExitCodeProcess hProc, iExitCode

' Wait for process but relinquish time slice
Do While iExitCode = STILL_ACTIVE
DoEvents
GetExitCodeProcess hProc, iExitCode
Loop
End If

CloseHandle hProc
WaitForProcess = iExitCode ' Return exit code
End Function




mvh
///JJ




Søg
Reklame
Statistik
Spørgsmål : 177501
Tips : 31968
Nyheder : 719565
Indlæg : 6408522
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste