Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Warten bis Programm beendet ist

Empfohlene Antworten

Veröffentlicht

Hi, ich rufe ein Programm aus meinem Programm auf und möchte wissen wann es beendet wird.

ShellExecute( NULL, "open", csProgramm, csParameter, NULL, SW_HIDE );
Ich habe eine Beispiel in der MSDN gefunden "Wait until a program closes". Aber ich werde daraus überhaupt nicht schlau. Ist wie chinesisch für mich. Denke das hier ist die entscheidende Stelle:
    Else

        '// start notepad

        lngTask = Shell("notepad " & App.Path & "wait.txt", vbNormalFocus)  'Start the task

        '// get the window's hWnd

        lNotePadhWnd = GetForegroundWindow

        '// get a handle on the window

        pHandle = OpenProcess(SYNCHRONIZE, False, lngTask)   'Get the task handle

        '// set the status

        lblStatus.Caption = "Waiting for notepad to close..."

        lblStatus.Refresh

        cmdNotepad.Caption = "Close Notepad"

        Do

            '// loop until the program closes

            '// you can pass INFINITE instead of 0 if you wish, and your

            '// program will 'hang' here until the program is finished

            lRet = WaitForSingleObject(pHandle, 0)

            DoEvents

        Loop While lRet <> 0

        '// program closes

        lblStatus.Caption = "Notepad closed."

        cmdNotepad.Caption = "Run Notepad"

    End If

Hier der ganze Code: Wait until a program closes - Developer Fusion, the UK developer community - VB, ASP, C#, .NET, PHP and XML tutorials & source code

Könnt Ihr mir helfen wie ich das für mein ShellExecute anpassen kann?

Was ist denn "lngTask" Für ein Variablentyp? Hoffe Ihr könnts mir etwas erklären...

ODER

Geht das vielleicht irgendwie mit WaitForSingleObject ?

Gruß Filou

Danke für den Tipp!

Schau mal, wieso funktioniert das so nicht?

	SHELLEXECUTEINFO App;

	App.lpDirectory = csQuellpfad;

	App.lpFile = "rar.exe";

	App.lpParameters = csParameter;

	App.nShow = SW_HIDE;


	if(ShellExecuteEx(App)&&App.hProcess!=NULL) 

	{ 

		while (bCheck == TRUE)

		{

		dWait = WaitForSingleObject(App.hProcess, 1000);

		if (dWait == WAIT_ABANDONED)

			{

			bCheck = FALSE;

			}

		Sleep(2000);

		}

	}

Bekomme die Medlung:

Konvertierung des Parameters 1 von 'struct _SHELLEXECUTEINFOA' in 'struct _SHELLEXECUTEINFOA *' nicht moeglich

Solltest du nicht inzwischen in der Lage sein, so ein grundlegendes Problem mit Hilfe der Doku und der Fehlermeldung selbst zu lösen :confused:

ShellExecuteEx will einen Zeiger auf eine SHELLEXECUTEINFO-Struktur. Das steht in der MSDN Library, und die Fehlermeldung sagt es auch nochmal.

Du musst aber auch alle relevanten Member der Struktur mit Werten füllen. fMask, cbSize und lpVerb sind das mindeste. Alles, was du nicht brauchst, solltest du mit 0 initialisieren. Am besten setzt du gleich beim Anlegen alles auf 0:

SHELLEXECUTEINFO App = {0};

Ok, habs gerade auch gemerkt ;)

Kannst Du mir sagen wie ich hProcess initialisieren muss?

habe jetz für

App.cbSize = 5000; //Len(App);

App.fMask = SEE_MASK_INVOKEIDLIST;

Stand so in der hilfe, nur dass das Len bei mir unbekannt ist. also hab ich mal ne Zahl genommen zum test...

Kannst Du mir sagen wie ich hProcess initialisieren muss?
Gar nicht. Steht auch in der MSDN Library. Da steht übrigens auch, dass du SEE_MASK_NOCLOSEPROCESS benutzen musst, damit du überhaupt ein Handle bekommst.

Stand so in der hilfe, nur dass das Len bei mir unbekannt ist. also hab ich mal ne Zahl genommen zum test...
Da steht doch: Size of the structure, in bytes. Also sizeof(SHELLEXECUTEINFO).

Ich danke Dir!

Hat geklappt!!

PS: Kann ich irgendwie die Prozesspriorität für die Anwendung einstellen, die geöffnet wird?

A)

folgendes ...


while (bCheck == TRUE)

{		 

   dWait = WaitForSingleObject(App.hProcess, 1000);

   if (dWait == WAIT_ABANDONED)

   {

      bCheck = FALSE;

   }

Sleep(2000);

}

... könnte noch ersetzt werden durch

while (WaitForSingleObject(App.hProcess, INFINITE) != WAIT_OBJECT_0) ;

// Process beendet

B)

Um die Priorität deines Processes zu ändern benötigst du - wie mein Vorredner schon dachte - CreateProcess

Da nicht klar ist, ob es sich um eine reine Konsolenanwendung oder eine Anwendung mit Fenstern handelt, noch ein Hinweis: Sobald Nachrichten verarbeitet werden müssen, darf im nachrichtenverarbeitenden Thread (GUI-Thread) nicht beliebig lange gewartet werden ohne die Nachrichten abzuarbeiten.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.