CreateProcess ... wieder mal



  • Hier dieses Tutorial habe ich benutzt, auch diese Varianten -sogar mit Notepad- funktionieren nicht.

    -by the way.. ich habe Vista-

    Also, ich habe natürlich bei MSDN nur nach CreateProcess geschaut.. ich wusste nicht dass die wirklich noch so eine Fette beschreibung da haben.

    Ich habe da mal drübergeschaut und ich verstehe nicht wieso die da argv[1] verwednen.
    Ich benutze in diesem Fall keine Argumente.

    Jochen Kalmbach schrieb:

    Der zweite Parameter *muss* beschreibbar sein!

    Was meinst du damit?

    Der wird doch nicht verändert oder?
    Was soll ich da deiner meinung nach hinschreiben, wenn ich keine Argumente benutze?

    if( CreateProcess( "C:\\Windows\\System32\\cmd.exe", "", NULL, NULL, FALSE, 0, NULL, NULL, &startUpInfo, &programInfo ) )
    		WriteToLog( "Server started." );
    

    startUpInfo und programInfo sind genau gleich wie si und pi.
    Auch diese Variante funktioniert nicht.



  • sry aber:
    Ich habe mal in den Task-Manager geschaut:
    es wird nach CreateProcess 5 sek geschlafen, in diesen 5 Sek ist ein neuer Prozes szu sehen "dllhost.exe" der geht auch wieder weg nach 5 sek.

    Er erscheint immer dann wenn ich den Dienst starte, oder beende.

    [EDIT]

    WriteToLog( "Try to start server:" );
    
    	if( CreateProcess( "C:\\Windows\\System32\\notepad.exe", "notepad", NULL, NULL, FALSE, 0, NULL, NULL, &startUpInfo, &programInfo ) )
    	{
    		WaitForSingleObject( programInfo.hProcess, INFINITE );
    		WriteToLog( "Server started." );
    	}
    	else
    	{
    		WriteToLog( "Cant start server.\n\n" );
    		exit(-1);
    	}
    

    er schreibt nicht weiter als "Try to start server:"

    Logfile schrieb:

    [Mon Jan 07 10:50:15 2008]: Service Started
    [Mon Jan 07 10:50:15 2008]: Try to start server:
    [Mon Jan 07 10:50:24 2008]: Service stopped: Service stoped by Controlpanel

    Ich habe halt den Prozess von Hand abgeschaltet, aber auch erst nach 10 Sekunden.
    Wieso tut er nichts weiter?


  • Mod

    Du kannst keine interaktiven Programme aus einem Service starten. Sobald diese auf eine Eingabe warten werden diese terminiert...

    Das ehe ich jetzt erst, dass Du mit cmd und Notepad experimentierst!



  • Naja dass ist ja nur Testweise...

    Was soll, oder kann ich den Testweise Starten? Gleich mein Serverprogramm?

    Das will keine Eingabe, dass wartet auf ne Netzwerkübertragung...

    if( CreateProcess( "C:\\NaDiA\\server.exe", "server", NULL, NULL, FALSE, 0, NULL, NULL, &startUpInfo, &programInfo ) )
    	{
    		WriteToLog( "Wait for complete start:" );
    		ret = WaitForSingleObject( programInfo.hProcess, INFINITE );
    
    		if( WAIT_ABANDONED == ret )
    			WriteToLog( "Server start-failure: WAIT_ABANDONED." );
    		else if( WAIT_OBJECT_0 == ret )
    			WriteToLog( "Server started." );
    		else if( WAIT_TIMEOUT == ret )
    			WriteToLog( "Server start-failure: WAIT_TIMEOUT." );
    		else if( WAIT_FAILED == ret )
    			WriteToLog( "Server start-failure: WAIT_FAILED." );
    	}
    	else
    	{
    		WriteToLog( "Cant start server.\n\n" );
    		exit(-1);
    	}
    

    [edit]

    WriteToLog( "Try to start server..." );
    
    	if( CreateProcess( _T("C:\\NaDiA\\server.exe"), _T("server"), NULL, NULL, FALSE, 0, NULL, NULL, &startUpInfo, &programInfo ) )
    	{
    		WriteToLog( "Wait for complete start:" );
    		ret = WaitForSingleObject( programInfo.hProcess, 10000 );
    
    		if( WAIT_ABANDONED == ret )
    			WriteToLog( "Server start-failure: WAIT_ABANDONED." );
    		else if( WAIT_OBJECT_0 == ret )
    			WriteToLog( "Server started." );
    		else if( WAIT_TIMEOUT == ret )
    			WriteToLog( "Server start-failure: WAIT_TIMEOUT." );
    		else if( WAIT_FAILED == ret )
    			WriteToLog( "Server start-failure: WAIT_FAILED." );
    		else
    			WriteToLog( "Server start-failure: Undefined." );
    	}
    	else
    	{
    		WriteToLog( "Cant start server.\n\n" );
    		exit(-1);
    	}
    

    ==

    [Mon Jan 07 11:21:17 2008]: Service Started
    [Mon Jan 07 11:21:17 2008]: Try to start server...
    [Mon Jan 07 11:21:17 2008]: Wait for complete start:
    [Mon Jan 07 11:21:27 2008]: Server start-failure: WAIT_TIMEOUT.
    [Mon Jan 07 11:21:27 2008]: Sleep 5 sec.
    [Mon Jan 07 11:21:32 2008]: Try to terminate server:
    [Mon Jan 07 11:21:32 2008]: Server terminated.
    [Mon Jan 07 11:21:32 2008]: Service works.
    [Mon Jan 07 11:21:41 2008]: Service stopped: Service stoped by Controlpanel

    Er wartet 10 Sekunden und dann gehts weiter...



  • Der zweite Parameter muss aber immer noch beschreibbar sein...



  • Und ich frage mich immernoch was du damit meinst... Kannst du mir dass bitte sagen?

    Soll dass ein Array sein?



  • nein, der zweite parameter darf keine konstante sein sondern muss eine variable sein..
    so ist es besser:

    CString cmdLine = "C:\\NaDiA\\server.exe server";
    if( CreateProcess( NULL, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &startUpInfo, &programInfo ) )
    
    //usw...
    

    da du unter vista arbeitest, kann es aber trotzdem probleme mit dem normalen createprocess geben, wegen eingeschränkter user und so.. kann grad nicht nachkucken, aber da gabs irgendeine lösung.. google mal nach "vista createprocess" oder so... hatte glaube auf codeproject mal was gesehen...



  • Wo ist den CString definiert?
    Mein Compiler motzt, weil er dass nicht kennt.

    Auf jeden Fall nicht in der String.h



  • Ansonsten einfach mal ein GetLastError(); hinter CreateProcess haengen und schon wirste wissen woran es lag.



  • schonmal was von der msdn gehört? 😉

    MSDN schrieb:

    A CString object consists of a variable-length sequence of characters. CString provides methods and operators using a syntax similar to that of Basic. Concatenation and comparison operators, together with simplified memory management, make CString objects easier to use than ordinary character arrays.

    CString does not have a base class.

    CString objects also have the following characteristics:

    CString objects can grow as a result of concatenation operations.
    CString objects follow, value semantics. Think of a CString object as an actual string, not as a pointer to a string.
    You can freely substitute CString objects for const char* and LPCTSTR function arguments.
    A conversion operator gives direct access to the characters of the string as a read-only array of characters (a C-style string).
    Tip Where possible, allocate CString objects on the stack rather than on the heap. This saves memory and simplifies parameter passing.
    CString assists you in conserving memory space by allowing two strings sharing the same value also to share the same buffer space. However, if you attempt to change the contents of the buffer directly (not using MFC), you can alter both strings unintentionally. CString provides two methods, CString::LockBuffer and CString::UnlockBuffer, to help you protect your data. When you call LockBuffer, you create a copy of a string, then set the reference count to –1, which locks the buffer. While the buffer is locked, no other string can reference the data in that string, and the locked string will not reference another string. By locking the string in the buffer, you ensure that the exclusive hold of the string on the data remains intact. When you have finished with the data, call UnlockBuffer to reset the reference count to 1.

    Remarks

    Windows CE does not support the following methods of the CString class:

    AnsiToOem
    Collate
    FormatMessage
    OemToAnsi
    Requirements

    Windows CE versions: 1.0 and later
    Header file: Declared in Afx.h

    also afx.h includen, oder auch windows.h



  • cmd.exe schrieb:

    mySvc.c:9:17: Afx.h: No such file or directory
    mySvc.c: In function ServiceMain': mySvc.c:47: error:CString' undeclared (first use in this function)
    mySvc.c:47: error: (Each undeclared identifier is reported only once
    mySvc.c:47: error: for each function it appears in.)
    mySvc.c:47: error: syntax error before "name"
    mySvc.c:102: error: `name' undeclared (first use in this function)

    windows.h ist schon längst eingebunden.
    Tja und afx.h kennt er nicht...

    MSDN habe ich vergessen tut mir leid.

    Ich habe in mein LogFile mal GetLastError schreiben lassen.

    183 !?

    Könnt ihr damit was anfangen?
    Wenn nicht:

    MSDN schrieb:

    ERROR_ALREADY_EXISTS
    183
    0xB7
    Cannot create a file when that file already exists.

    Ich lege keine Datei an oder!?



  • also mein compiler kennt <afx.h> schon...

    lies mal dashier, ich hab leider keine zeit:http://www.mser.net/microsoft-developer-network/29/visual-c++-programming-c++-winapi-296984.shtm



  • Ich nutze den MinGW, der dass wahrscheinlich einfach verpeilt oder so.

    Ich habe folgendes gemacht:

    if( CreateProcess( NULL, "\"C:\\NaDiA\\server.exe server\"", NULL, NULL, FALSE, 0, NULL, NULL, &startUpInfo, &programInfo ) )
    	{
    		WriteToLog( "Wait for complete start:" );
    		ret = WaitForSingleObject( programInfo.hProcess, 15000 );
    
    		if( WAIT_ABANDONED == ret )
    		{
    			WriteToLog( "Server start-failure: WAIT_ABANDONED." );
    			error = 1;
    		}
    		/*else if( WAIT_OBJECT_0 == ret )
    		{
    			WriteToLog( "Server start-failure: WAIT_OBJECT_0" );
    			error = 1;
    		}*/
    		else if( WAIT_TIMEOUT == ret )
    		{
    			WriteToLog( "Server start-failure: WAIT_TIMEOUT." );
    			error = 1;
    		}
    		else if( WAIT_FAILED == ret )
    		{
    			WriteToLog( "Server start-failure: WAIT_FAILED." );
    			error = 1;
    		}
    		else
    		{
    
    			WriteToLog( intToChar( GetLastError() ) );
    			error = 1;
    		}
    	}
    	else
    	{
    		WriteToLog( "Cant start server." );
    		error = 1;
    	}
    

    Jetzt kommt beim Log:

    LogFile schrieb:

    [Mon Jan 07 13:30:30 2008]: Service Started
    [Mon Jan 07 13:30:30 2008]: Try to start server...
    [Mon Jan 07 13:30:30 2008]: Cant start server.
    [Mon Jan 07 13:30:30 2008]: Failure detectet.
    [Mon Jan 07 13:30:30 2008]: Service shuting down.

    Dass ist schonmal ein gewisser fortschritt, denn bis jetzt hat er immer behauptet, der Server könne gestartet werden.
    Fällt einem da irgendwas komisches auf, wass nicht stimmen könnte?

    DANKE FÜR ALL DIE ANTWORTEN... IHR SEID SPITZE...

    [edit]Beim Servicestart wird angesagt, dass der Service beendet werden musste... Warum auch immer.



  • der zweite parameter von createprocess muss eine variable sein, wie oft muss das dann noch gesagt werden? 😉
    Hatte ich in meinem Beispiel auch gezeigt...

    mit MinGW kenn ich mich nicht aus, da ich nur schlechte sachen gehört hab davon 😉



  • Also:
    Ich habe schon längst folgendes versucht:

    char name[50];
    
    	[...]
    
    	memset( name, 0, sizeof(name) );
    
    	strcpy( name, "\"C:\\NaDiA\\server.exe server\"" );
    
    [...]
    if( CreateProcess( NULL, name, NULL, NULL, FALSE, 0, NULL, NULL, &startUpInfo, &programInfo ) )
    	{
    		WriteToLog( "Wait for complete start:" );
    

    geht auch nicht.

    [edit]Bitte beachten: ich programmiere in C



  • Rückgabewert? GetLastError()?



  • Rückgabewert von GetLastError = 183,
    siehe 6 Posts weiter oben.

    Danke schonmal...



  • HeyHo...

    Wie es scheint ist das 2te Argument von 'WaitForSingleObject' für die 'Lebensdauer' eines Prozesses zuständig.
    Wenn dem so ist, läuft mein Prozess 15 Sekunden.

    Denn in diesem Zeitfenster kann ich Nachrichten senden und erhalte den Hinweis dass die Nachricht erfolgreich versendet wurde.

    FRAGE:
    Kann dieser kreirte Prozess eine MessageBox anzeigen?

    Wenn nein raste ich aus... Denn dann habe ich umsonst gearbeitet.

    Danke nochmals für alle Beiträge, und alle die noch kommen werden.


  • Mod

    Nochmal: Ein Service kann so einfach keine interaktiven Programm starten, die auf Deinem Desktop sichtbar werden!



  • der prozess, den du startest, kann alles machen, was er will, es ist ja ein eigenständiger prozess...

    EDIT: oh, es handelt sich um einen service.. sorry das hatte ich übersehen... dann ist das natürlich nicht so einfach möglich...


Anmelden zum Antworten