Problem mit Shellexecute und Winexec

MafiaLuigi

Grünschnabel
Ich bin dabei für einen freund ein programm zu schreiben welches von einem link im Internet zB TMN://|192.168.0.1 eine ip bekommt und die an die exe von trackmania weiterleitet damit man via Link direkt zum Server konnekten kann. Mit dem Protokoll gabs keine Probleme ich bekomme die ip soweit ist alles in ordnung. Wenn ich nun aber mit shellexecute oder winexec mit oder ohne Parameter die exe aufrufe startet Trackmania und schliesst sich sofort. Ich habe es aus testzwecken dann noch mit anderen Programmen probiert die meisten klappen aber HLSW hat auch eine fehlermeldung. Woran kann es liegen Doppelklick klappt aber aufruf über Shellexecute und Winexec nicht :confused:
Hab ich in VC++ 6.0 und der version 2005 ausprobiert

ShellExecute(NULL,"Open","D:\\TrackMania Nations ESWC\\TmNationsESWC.exe",NULL,NULL,SW_SHOW);

WinExec("D:\\TrackMania Nations ESWC\\TmNationsESWC.exe",SW_SHOW);
 
Hi.

Ich zitiere mal von der MSDN Seite:
Security Remarks

The executable name is treated as the first white space-delimited string in lpCmdLine. If the executable or path name has a space in it, there is a risk that a different executable could be run because of the way the function parses spaces. The following example is dangerous because the function will attempt to run "Program.exe", if it exists, instead of "MyApp.exe".

WinExec("C:\\Program Files\\MyApp", ...)

If a malicious user were to create an application called "Program.exe" on a system, any program that incorrectly calls WinExec using the Program Files directory will run this application instead of the intended application.

To avoid this problem, use CreateProcess rather than WinExec. However, if you must use WinExec for legacy reasons, make sure the application name is enclosed in quotation marks as shown in the example below.

WinExec("\"C:\\Program Files\\MyApp.exe\" -L -S", ...)

WinExec gibt übrigens einen Fehlerwert zurück den man überprüfen sollte. CreateProcess gibt einen boolschen Wert zurück, wenn der False ist, kann man den Fehler mit GetLastError() abfragen.

Gruß
 
Hab es nun mal mit CreateProcess probiert aber ich hab immer noch das Problem das sich die exe von Trackmania Nations sofort nach dem aufruf wieder schliesst hat da niemand einen Tipp wodrann es liegt er findet ja die Datei sonst würd er sie nicht starten und wieder schliessen.

CreateProcess( NULL, // No module name (use command line).
"D:\\TrackMania Nations ESWC\\TmNationsESWC.exe", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.


Bei HLSW öffnet er es auch wieder mit fehlermeldung und dort ist kein space in dem pfad D:\\HLSW\\hlsw.exe dort kommt die fehlermeldung Coud not load config file in cfg ... die bei einem doppelklick auf hlsw.exe nicht erscheint also wo liegt der unterschied zwischen shellexecute, winexec, createprozess gegenüber einem doppelklick.
 
Zuletzt bearbeitet:
Normalerweise wird das Programm beim Doppelklick in dem Verzeichnis ausgeführt wo es sich befindet. Wenn du das Programm mit einer Win API Funktion aufrufst, wird das Programm in dem Verzeichnis gestartet wo die Anwendung gerade läuft.

Du kannst die Funktion BOOL SetCurrentDirectory(LPCTSTR lpPathName) benutzen um das Verzeichnis erst zu wechseln bevor du das Programm startest.

Gruß
 
Zurück