Shellx Funktion

  • VB.NET

Es gibt 4 Antworten in diesem Thema. Der letzte Beitrag () ist von thecracked.

    Shellx Funktion

    Hi,

    ich will über eine form mit einem Klick auf einen button eine .exe ausführen. Sobald die .exe fertig ist, soll eine Meldung erscheinen.
    Google hat mir dann die Funktion "shellx" vorgeschlagen. Dies soll mir eine Rückmeldung geben, wann die .exe bzw der Prozess fertig ist.
    Bekomm dies jedoch nicht hin.

    Diesen Code habe ich gefunden, die die Funktion shellx integrieren soll. Jedoch kennt mein VB z.b. "VAppWinStyle" nicht.


    VB.NET-Quellcode

    1. Private Declare Function CloseHandle Lib "kernel32" ( _
    2. ByVal hObject As Long) As Long
    3. Private Declare Function GetExitCodeProcess Lib "kernel32" ( _
    4. ByVal hProcess As Long, ByVal lpExitCode As Long) As Long
    5. Private Declare Function OpenProcess Lib "kernel32" ( _
    6. ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
    7. ByVal dwProcessId As Long) As Long
    8. ' ShellX stellt eine Erweiterung der Shell-Funktion von VBA dar, die es erlaubt,
    9. ' das Ende des ausgeführten Prozesses abzuwarten
    10. Public Function ShellX( _
    11. ByVal PathName As String, _
    12. Optional ByVal WindowStyle As VAppWinStyle = vbMinimizedFocus, _
    13. Optional ByVal Events As Boolean = True _
    14. ) As Long
    15. 'Deklarationen:
    16. Const STILL_ACTIVE = &H103&
    17. Const PROCESS_QUERY_INFORMATION = &H400&
    18. Dim ProcId As Long
    19. Dim ProcHnd As Long
    20. 'Prozess-Handle holen:
    21. ProcId = Shell(PathName, WindowStyle)
    22. ProcHnd = OpenProcess(PROCESS_QUERY_INFORMATION, True, ProcId)
    23. 'Auf Prozess-Ende warten:
    24. Do
    25. If Events Then DoEvents()
    26. GetExitCodeProcess(ProcHnd, ShellX)
    27. Loop While ShellX = STILL_ACTIVE
    28. 'Aufräumen:
    29. CloseHandle(ProcHnd)



    Ich hoffe ihr könnt mir weiter helfen.
    Vergiss ShellX, nimm Process.

    VB.NET-Quellcode

    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2. Dim p As New Process()
    3. AddHandler p.Exited, AddressOf processExited
    4. p.StartInfo.FileName = "Notepad.exe"
    5. p.StartInfo.CreateNoWindow = True
    6. p.StartInfo.UseShellExecute = False
    7. p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    8. p.EnableRaisingEvents = True
    9. p.Start()
    10. End Sub
    11. Private Sub processExited(ByVal sender As Object, ByVal e As EventArgs)
    12. MessageBox.Show("Notepad wurde gestoppt")
    13. End Sub
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Danke für die Antwort.

    ich bekomm bei mir die Fehlermeldung, dass die datei nicht gefunden wurde.
    Mein Problem liegt jetzt denke ich mal daran, dass ich noch Parameter mit der exe mit gebe.

    Quellcode

    1. Dim all As String
    2. all = ProgrammPfad & Para
    3. MsgBox(all)
    4. Dim p As New Process()
    5. AddHandler p.Exited, AddressOf processExited
    6. p.StartInfo.FileName = all
    7. .......


    der Aufruf sieht dann so aus:

    Quellcode

    1. programm.exe 4 0 eins.dat zwei.dat


    Gebe ich nur die exe an, dann funktioniert das. Ich benötige jedoch noch die nachstehenden Parameter für die exe
    Das hättest Du aber locker allein rauskriegen können.

    VB.NET-Quellcode

    1. p.StartInfo.Arguments = "c:\temp\bla.txt"
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!