[VB] vraag over het gebruik van PID nummers *

Pagina: 1
Acties:

  • bladeoner112
  • Registratie: Oktober 2003
  • Laatst online: 12-04-2017
Ik wil graag PID nummers gebruiken in een VSB programma, hoe kan ik dit het beste doen. Mijn doel is om een programma op te starten en af te kunnen sluiten dit wil ik met PID nummers doen of op een andere manier als iemand die weet. Het gaat erom dat ik elk programma af kan sluiten wat er is en dat is niet alleen Excel en Word enz, want hier had ik al een ander alternatief voor gevonden. Mijn programma bestaat uit 2 radiobuttons waar ik 2 bestaande programma's aan heb gekoppeld en een 'open application button' en een 'close application button'. Als iemand een oplossing heeft hoor ik dit graag.

Alvast bedankt.

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 12-05 22:23

curry684

left part of the evil twins

Lees jij sluitmsges ook wel? :/

En leg eens wat beter uit wat je wilt want hier is niet veel aan vast te knopen... :)

Professionele website nodig?


  • ginamri
  • Registratie: Augustus 2000
  • Laatst online: 10-09-2024
findwindow gebruiken, je krijgt een handle terug, daar moet je een bericht naar sturen met sendmessage/postmessage wm_quit. Ik ben geen vb-er that's it..

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 12-05 22:23

curry684

left part of the evil twins

Ginamri schreef op 06 januari 2004 @ 13:07:
findwindow gebruiken, je krijgt een handle terug, daar moet je een bericht naar sturen met sendmessage/postmessage wm_quit. Ik ben geen vb-er that's it..
VSB = Visual Basic? * curry684 zat zich al af te vragen wat VSB in godesnaam was 8)7

Professionele website nodig?


  • bladeoner112
  • Registratie: Oktober 2003
  • Laatst online: 12-04-2017
curry684 schreef op 06 januari 2004 @ 12:56:
Lees jij sluitmsges ook wel? :/

En leg eens wat beter uit wat je wilt want hier is niet veel aan vast te knopen... :)
ik wil een uit 2 programma's kiezen die ik kan opstarten met knop 1 en als ik dan weer dat programma kies met die radio button en op knop 2 druk dat het programma weer sluit.

  • kvdveer
  • Registratie: November 2000
  • Laatst online: 06-11-2025

kvdveer

Z.O.Z.

In dat geval zul je waarschijnlijk moeten werken met findwindow en een WM_CLOSE berichtje.
Ik zou namelijk niet weten hoe je met een exec call, het procesnummer kan achterhalen.

Hoe was je van plan "app launching app" op te lossen (zoals k++), dan is namelijk de app die je opstart niet dezelfde als die je wilt sluiten...

Localhost, sweet localhost


Verwijderd

Je kunt bij het starten van de processen toch gewoon het process id opvragen. Als je deze hebt kun je ook weer de goede afsluiten. Of snap ik het verhaal nu weer niet :X

  • henkleerssen
  • Registratie: December 2000
  • Niet online

henkleerssen

Your life is as you narrate it

Verwijderd schreef op 06 januari 2004 @ 14:40:
Je kunt bij het starten van de processen toch gewoon het process id opvragen. Als je deze hebt kun je ook weer de goede afsluiten. Of snap ik het verhaal nu weer niet :X
hij wil waarschijnlijk gewoon wat code zien...
Visual Basic:
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
70
71
72
73
74
75
76
77
78
79
80
81
82
'Structure startup properties for the application to install
Private Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    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

'structure for info of thread
Private Type PROCESS_INFORMATION 'from MSDN
        hProcess As Long
        hThread As Long
        dwProcessID As Long
        dwThreadID As Long
End Type


Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA Lib "kernel32" (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 lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long



Public Sub ExecCmd(cmdline$)
'*******************************************************************************
'Effects:       Starts up the application in the commandline and gives control back to application
'               when application is finished (process based)
'Input:         Command line (path and file with optional parameters
'Output:        NA
'Note:          Changed sample code from MSDN
'*******************************************************************************

    Dim proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO
    Dim ReturnValue As Integer
    
    On Error GoTo hell
    
    ' Initialize the STARTUPINFO structure:
    start.cb = Len(start)
    
    ' Start the shelled application:
    ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

    ' Wait for the shelled application to finish:
    Do
        'ReturnValue=258 > program opened
        ReturnValue = WaitForSingleObject(proc.hProcess, 0)
        'ReturnValue=0 > program closed
        
        'program not found!
        If ReturnValue = -1 Then
            GoTo hell 'Err.Raise vbObjectError + ERROR_EXEC_PROC
        End If
        
        DoEvents
        
    Loop Until ReturnValue <> 258

    ReturnValue = CloseHandle(proc.hProcess)
Exit Sub
hell:
    MsgBox "Something went wrong. Is the path '" & cmdline$ & "' correct?", vbCritical
End Sub

Formpje erbij plakken met radiobuttons en paths voor cmdline$ variabele.... et voilá

ID kun je ook nog lezen.. maar heb je eigenlijk niet meer nodig met het voorbeeld.. gewoon van MSDN

  • Luppie
  • Registratie: September 2001
  • Laatst online: 01-03 23:21

Luppie

www.msxinfo.net

Ik doe het zelf altijd op de volgende manier (WMI) dit gaat niet met het PID met met de procesname.

code:
1
2
3
4
5
6
7
8
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'calculator.exe'")
For Each objProcess In colProcessList
objProcess.Terminate()
Next


In dit voorbeeld word calculator.exe afgesloten.

Heb je iets aan mijn antwoord ? Een thumbs-up wordt zeker op prijs gesteld.


Verwijderd

Cobra_Lup schreef op 06 januari 2004 @ 15:01:
Ik doe het zelf altijd op de volgende manier (WMI) dit gaat niet met het PID met met de procesname.
Kan wel met PID ;)

Visual Basic:
1
2
3
4
5
6
7
8
9
// Get a process on the local computer, using the process id.
Process localById = Process.GetProcessById(1234);

// Get all processes running on the local computer.
Process [] localAll = Process.GetProcesses();

// Get all instances of Notepad running on the local
// computer.
Process [] localByName = Process.GetProcessesByName("notepad");


Zo 3 manieren om de processes te laden. Zoek heel even met google of blader ff door MSDN. Good luck!

edit:
Gebruik je trouwens VB6 of VB.NET was mij nietecht duidelijk...

[ Voor 7% gewijzigd door Verwijderd op 06-01-2004 15:16 ]


  • Cai
  • Registratie: December 2001
  • Laatst online: 15-05 09:47

Cai

Volgens mij vraagt tie niet voor het laden, maar om te killen

Verwijderd

Cai schreef op 06 januari 2004 @ 16:26:
Volgens mij vraagt tie niet voor het laden, maar om te killen
Als hij de proces in een vari heeft. Kan ie er toch mee doen wat hij wil... dus ook process.Terminate() B)

  • henkleerssen
  • Registratie: December 2000
  • Niet online

henkleerssen

Your life is as you narrate it

hij vraagt dus om opstarten EN killen (met CloseHandle(proc.hProcess)) .. dussum
Pagina: 1