[VB6] Running processes list: Bug?

Pagina: 1
Acties:

  • Battle Bunny
  • Registratie: Oktober 2001
  • Laatst online: 02-02 21:41
In een applicatie moet ik een andere app starten, en monitoren (wachten totdat 'ie afgesloten is). Dit doe ik door een timertje elke seconde te laten kijken of die app nog draait. Het vreemde is, dat wanneer het programma dat ik monitor actief is, deze verdwijnt uit de "running processes" lijst!

code:
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
    Dim ThisAppHandle As Long
    Dim NextAppHandle As Long
    Dim AppClassName As String
    
    List1.Clear
    
    'Get your current application owner's
    'handle
    ThisAppHandle = getwindow(frmLogin.hWnd, GW_OWNER)
    'Pass it on as a seed for the next handle
    'so all the windows in the z order can be
    'searched
    NextAppHandle = ThisAppHandle
    'Perform the iterations in the Z order till
    'all the running applications (either foreground
    'or background) have been run through
    Do While NextAppHandle <> 0
        DoEvents
        'Get the handle of the next window
        'in the Z order
        NextAppHandle = getwindow(NextAppHandle, GW_HWNDNEXT)
        'Retrieve its window's classname
        List1.AddItem GetAppClassName(NextAppHandle)

    Loop


Getest met meerdere apps. Zodra je een appl. actief maakt, verdwijnt deze uit de list1! Is dit een bug of normaal gedrag?

Verwijderd

Ik heb zelf ook wel eens zoiets gemaakt, maar daarbij maakte ik gebruik van de API-functie ShellExecuteEx ( om het programma te starten, en een handle naar het process ervan terug te krijgen ) en de API-functie GetExitCodeProcess ( om te kijken of het nog draait ).

Code kan ik eventueel wel posten, als je interesse hebt.

  • Battle Bunny
  • Registratie: Oktober 2001
  • Laatst online: 02-02 21:41
FFrenzy: Graag! Overigens kan ik niet WaitForSingleObject gebruiken, omdat de launch app dan blijft hangen (terwijl de gellaunchede app draait)

Verwijderd

wat betreft je WaitForSingleObject : Daarom gebruik ik ook ShellExecuteEx !!!

Maar hier is de code. Gewoon in een module plakken, en je hebt beid e functies die je nodig hebt. Executeprocess geeft de handle naar het process terug ( of 0 indien het niet gestart kon worden ). Ik neem aan dat je zelf verer wel het programma eromheen kunt maken.

Laat me weten of het geholpen heeft....

code:
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
59
60
61
62
63
64
65
66
67
68
69
Private Type SHELLEXECUTEINFO
    cbSize        As Long
    fMask         As Long
    hwnd          As Long
    lpVerb        As String
    lpFile        As String
    lpParameters  As String
    lpDirectory   As String
    nShow         As Long
    hInstApp      As Long
    lpIDList      As Long     'Optional parameter
    lpClass       As String   'Optional parameter
    hkeyClass     As Long     'Optional parameter
    dwHotKey      As Long     'Optional parameter
    hIcon         As Long     'Optional parameter
    hProcess      As Long     'Optional parameter
End Type

Public Enum ShowTypes
  st_Shownormal = 1
  st_ShowMinimized = 2
  st_ShowMaximized = 3
  st_ShowMinNoActive = 4
End Enum

Const Still_active = 259 '&H102
Const SEE_MASK_NOCLOSEPROCESS = &H40

Private Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEx" _
  (SEI As SHELLEXECUTEINFO) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Public Function ExecuteProcess(Filename As String, Directory As String, Params As String, Showtype As ShowTypes) As Long

  ' Start een extern programma op, en geef de process handle terug
  ' Deze handle kan dan later worden gebruikt om te kijken of het programma
  ' nog draait
  ' Info^.cbSize:=SizeOf(Info^);
  ' Info^.fMask:=SEE_MASK_NOCLOSEPROCESS ;
  ' Info^.Wnd:=Form1.Handle;
  ' Info^.lpVerb:='open';
  ' Info^.lpFile:=PChar(mainprogram);
  ' Info^.lpParameters:=pchar(mainparams);
  ' Info^.lpDirectory:='';
  ' Info^.nShow:=SW_SHOW;
  Dim SEI As SHELLEXECUTEINFO
  With SEI
    .cbSize = Len(SEI)
    .fMask = SEE_MASK_NOCLOSEPROCESS
    .hwnd = 0
    .lpVerb = "open"
    .lpFile = Filename
    .lpDirectory = Directory
    .lpParameters = Params
    .nShow = Showtype
  End With
  If ShellExecuteEX(SEI) = 0 Then
    ' error
    ExecuteProcess = 0
  Else
    ExecuteProcess = SEI.hProcess
  End If
End Function

Public Function IsProcessrunning(prochandle As Long) As Boolean
  Dim Retval As Long
  Call GetExitCodeProcess(prochandle, Retval)
  IsProcessrunning = (Retval = Still_active)
End Function

  • Yoeri
  • Registratie: Maart 2003
  • Niet online

Yoeri

O+ Joyce O+

(overleden)
een handle blijft toch niet noodzakelijk hetzelfde gedurende de hele lifetime van een object/app als ik het goed voorheb?

iig werd ik hiervoor tijdens m'n eerste vakantiejob op de vingers getikt, omdat ik een handle gebruikte om iets terug te halen of zo (was toen wel een form geloof ik)

Kijkje in de redactiekeuken van Tweakers.net
22 dec: Onze reputatie hooghouden
20 dec: Acht fouten


Verwijderd

Robbedoeske schreef op 08 april 2004 @ 11:16:
een handle blijft toch niet noodzakelijk hetzelfde gedurende de hele lifetime van een object/app als ik het goed voorheb?

iig werd ik hiervoor tijdens m'n eerste vakantiejob op de vingers getikt, omdat ik een handle gebruikte om iets terug te halen of zo (was toen wel een form geloof ik)
Een handle naar een process blijft voor zover ik weet gelijk ( en die naar een form in vb ook volgens mij )

  • Battle Bunny
  • Registratie: Oktober 2001
  • Laatst online: 02-02 21:41
Perfect! Dit werkt top!

Vraag blijft wel: waarom dit vreemde gedrag in de process list?
Pagina: 1