03. maj 2004 - 09:33Der er
2 kommentarer og 1 løsning
Vente på andet program
Jeg har i et program et kald til et andet program, der skal synkronisere 2 databaser. Når synkroniseringen er overstået, vil jeg gerne have mit program opdateret, der læser fra den ene database. Men der skal ikke opdateres før synkroniseringen er overstået. Hvordan kan jeg få mit program til at vente indtil det andet program er afsluttet. (Synkroniseringsprogrammet afslutter automatisk)
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDriectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Long dwThreadId As Long End Type
Private Type STARTUPINFO cb As Long lpReserved As Long lpDesktop As Long lpTitle As Long dwX As Long dwY As Long dwXSize As Long dwYSize As Long dwXCountChars As Long dwYCountChars As Long dwFillAttribute As Long dwFlags As Long wShowWindow As Integer cbReserved2 As Integer lpReserved2 As Long hStdInput As Long hStdOutput As Long hStdError As Long End Type
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Function ShellAndWait(strCommandLine As String, lWait As Long) As Long Dim objProcess As PROCESS_INFORMATION Dim objStartup As STARTUPINFO Dim lResult As Long Dim lExitCode As Long
'try and Create the process lResult = CreateProcess(0, strCommandLine, 0, 0, 0, 0, 0, 0, objStartup, objProcess)
If lResult = 0 Then ShellAndWait = -1 Exit Function End If
'now, wait on the process
If lWait <> 0 Then lResult = WaitForSingleObject(objProcess.hProcess, lWait)
If lResult = 258 Then 'did we timeout? lResult = TerminateProcess(objProcess.hProcess, -1) lResult = WaitForSingleObject(objProcess.hProcess, lWait) End If End If
>>>mermermer Jeg får desværre en fejl, så jeg kan ikke engang checke om din kode virker. Jeg får en syntaks-fejl når jeg indtaster: ShellAndWait (App.Path & "\Synchronizer.exe",-1) VB forventer et lighedstegn et eller andet sted /Søren
Dim RetVal retval = ShellAndWait (App.Path & "\Synchronizer.exe",-1)
Prøv det.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.