Wachten op Shell

Pagina: 1
Acties:

  • sandergar
  • Registratie: Juni 2002
  • Laatst online: 21:17
Ik ben bezig met een VBA script die PKunzip.exe aanroept. Ik laat PKunzip een lijst maken en de bedoeling is dat ALS PKunzip klaar is dat ik deze lijst gelijk ga uitlezen met een "open for input" statement. Het probleem is echter dat mijn script niet wacht totdat PKunzip klaar is. Dit resulteert in een error daar het te lezen bestand nog niet bestaat ... Met het filesystem object kan ik wel controleren of het bestand aanwezig is maar niet of het al is afgesloten door PKunzip. Ik zoek dus een manier om te controleren op het Shell commando beeindigd is.

Ik heb het volgende gemaakt (beetje geknipt en geplakt voor mijn post):

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Function MakeZipList() As Boolean
    MakeZipList = Shell("DoSomething.exe", 1)
End Function

Function ReadZipFile(myZipList)
    Open myZipList For Input As #2
        Do While Not EOF(2)
            Input #2, myFile
        Loop
    Close #2
End Function

Sub Main()
    If MakeZipList() then
        ReadZipFile(myZipList)
    End if
End Sub

Op internet vond ik een antwoord ... maar dit werkt alleen in Access 2.0 ;( :

code:
1
2
3
4
5
6
7
8
9
10
11
12
Declare Function GetModuleUsage Lib "Kernel" (ByVal hModule As Integer) As Integer

Sub test()
Dim hModule As Integer

hModule = Shell("something.exe", 1)
Do While GetModuleUsage(hModule)
  DoEvents
Loop
DoCmd.Echo True, "This message will only come up when whatever.exe has finished"

End Sub


Weet iemand een manier om dit voor elkaar te krijgen met Access 2000? _/-\o_

2.730 Wp Enphase Zuid 30°, 4.450 Wp Enphase Noord 30° | Smart EVSE laadpaal | Victron Multiplus II 48/5000/70 3 Fase | 45kWh PylonTech Pelio accu


  • robjanssen
  • Registratie: September 2001
  • Laatst online: 02-08 16:10

robjanssen

Software Developer

Kun je niet proberen de file te openen voor te schrijven?
Dit lukt als het goed is niet, want PKUNZIP is er nog mee bezig.
Blijf dit net zo lang proberen tot het wel lukt en ga dan verder met je code.

  • johnwoo
  • Registratie: Oktober 1999
  • Laatst online: 21:46

johnwoo

3S-GTE

code:
1
2
3
4
5
6
7
8
Declare Function WaitForSingleObject Lib "kernel32" Alias "WaitForSingleObject" _
    (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

(...)

Dim hModule As Long
hModule = Shell("whatever.exe")
WaitForSingleObject hModule, -1


[edit]
Damn, ik ben het ff aan het testen maar het blijkt niet zo zonder meer te werken... ff debuggen :P

[ Voor 0% gewijzigd door johnwoo op 21-09-2002 14:13 . Reden: layout ]

4200Wp ZO + 840Wp ZW + 1680Wp NW | 14xIQ7+ + 1xDS3-L | MTVenusE | HWP1


  • sandergar
  • Registratie: Juni 2002
  • Laatst online: 21:17
Heb even gezocht op "WaitForSingleObject" en vond bij Microsoft de oplossing:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
      Private Declare Function GetModuleUsage% Lib "Kernel" _
         (ByVal hModule%)

      Private Function TestFunc(ByVal lVal As Long) As Integer
      'this function is necessary since the value returned by Shell is an
      'unsigned integer and may exceed the limits of a VB integer
         If (lVal And &H8000&) = 0 Then
           TestFunc = lVal And &HFFFF&
         Else
           TestFunc = &H8000 Or (lVal And &H7FFF&)
         End If
      End Function

      Sub Form_Click()
        lRet& = Shell("NOTEPAD.EXE")       ' Modify the path as necessary.
        x% = TestFunc(lRet&)
        While GetModuleUsage(x%) > 0    ' Has Shelled program finished?
           z% = DoEvents()              ' If not, yield to Windows.
        Wend
        MsgBox "Shelled application just terminated", 64
      End Sub


Bij het uitvoeren van dit script krijg ik de foutmelding "Fout 48, Kan het volgende bestand niet vinden: Kernel". :(
Helaas werkt het dus nog niet ....

2.730 Wp Enphase Zuid 30°, 4.450 Wp Enphase Noord 30° | Smart EVSE laadpaal | Victron Multiplus II 48/5000/70 3 Fase | 45kWh PylonTech Pelio accu


  • johnwoo
  • Registratie: Oktober 1999
  • Laatst online: 21:46

johnwoo

3S-GTE

sandergar schreef op 21 september 2002 @ 15:55:
[...]
Bij het uitvoeren van dit script krijg ik de foutmelding "Fout 48, Kan het volgende bestand niet vinden: Kernel". :(
Helaas werkt het dus nog niet ....
Probeer eens "kernel32" :)

4200Wp ZO + 840Wp ZW + 1680Wp NW | 14xIQ7+ + 1xDS3-L | MTVenusE | HWP1


  • sandergar
  • Registratie: Juni 2002
  • Laatst online: 21:17
Kernel32? Helaas ....
Fout 453: "Kan ingangspunt van DLL GetModuleUsage in Kernel32 niet vinden"

Nog meer ideeen?

2.730 Wp Enphase Zuid 30°, 4.450 Wp Enphase Noord 30° | Smart EVSE laadpaal | Victron Multiplus II 48/5000/70 3 Fase | 45kWh PylonTech Pelio accu


  • sandergar
  • Registratie: Juni 2002
  • Laatst online: 21:17
johnwoo bedankt voor de tip .... Microsoft heeft ook een voorbeeld voor een 32-bits omgeving :) Doet wonderen !!!! 8)7
De functie "GetModuleUsage" bestaat niet meer in de nieuwe versie. Info gevonden op: http://support.microsoft....px?scid=KB;EN-US;Q129796&

2.730 Wp Enphase Zuid 30°, 4.450 Wp Enphase Noord 30° | Smart EVSE laadpaal | Victron Multiplus II 48/5000/70 3 Fase | 45kWh PylonTech Pelio accu

Pagina: 1