CreateProcess ... wieder mal



  • 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...



  • Also...

    Service -> startet server.exe -> server.exe hört Port ab -> Nachricht kommt rein -> server.exe öffnet MessageBox und zeigt nachricht an...

    Ich habe mir extra 5273652 ewigkeiten angesehen wie ich diesen ***** ... sry... also:

    Ich habe mir gedacht wenn ich die *.exe Datei so aufrufe, geht dass. Anscheinend nicht.
    Wie bekomme ich dass hin?

    NetSend hats doch auch geschaft.


  • Mod

    Nochmal: Ein Service kann kein Programm starten das interaktiv ist!
    Soll ich es buchstabieren?

    Das ging mal... Seit Vista nicht mehr möglich, also schmink es Dir ab.
    Programm die so etwas machen wollen haben eine zweiteilung. Ein Programm was im Desktop des Users läuft und ein Programm im Kontext des (oder als) Service.

    http://support.microsoft.com/kb/327618



  • Omg.

    Wieso muss dass so komisch sein.
    Also was ich eigentlich nur haben will:
    eine MessageBox.

    Wie lasse ich 2 *.exe Dateien miteinander komunizieren, und wo soll der Unterschied sein, wenn beide von dem Service gestartet werden.

    Dürfen doch eh beide keine Messages anzeigen.

    Dass in dem Artikel ist irgendwie komisch. Ich verstehe dass nciht:
    Ist da ein Protokoll wass die Komunikation für mcih macht oder soll ich das selber machen?

    Gibt es irgendwo dazu ein Tutorial... Ich mache dass erste mal was mit Services und noch dazu was mit *.exe Dateien aufrufen.

    Kann mein Service die *.exe Datei so aufrufen dass sie die MessageBoxen anzeigen kann?
    Dass war ja ursprünglich dass Ziel.

    Danke schonmal.



  • Eine MessageBox kannst Du auch vom Service aus anzeigen:
    Siehe: WTSSendMessage

    Siehe auch: The Windows Vista Developer Story: Application Compatibility Cookbook
    http://www.microsoft.com/indonesia/msdn/appcomp.aspx


  • Mod

    Kann man nicht auch wie in dem Artikel, den ich gepostet habe, einfach MB_SERVICE_NOTIFICATION in MessageBox(Ex) verwenden?


Anmelden zum Antworten