ShellExecute mit String ?
-
Hi Community.
Ich befasse mich seid ner weile mit C++ und wollte fragen warum dieser Shellexecute befehl nicht klappt.
Ich hoffe auf Hilfe und würde mich freuen (:
Hier mal mein Code:#include <iostream> #include <string> #include <conio.h> #include <tchar.h> #include <windows.h> #include <direct.h> // for getcwd #include <sstream> using namespace std; int main(int argc, char** args) { string j1 = getenv("TEMP"); string j2 = ("\\IJumper"); string j3 = ("\\Programm.exe"); string j0 (j1 + j2 + j3); cout << j0 << "\n"; //ShellExecute(0, "open", pfad.c_str(), NULL, NULL, SW_SHOWNORMAL); ShellExecute( NULL, _T("open"), j0, _T("/console"), // Programm mit /console ausführen NULL, SW_MINIMIZE); cin.get(); return 0; }
-
System31 schrieb:
Hi Community.
Ich befasse mich seid ner weile mit C++ und wollte fragen warum dieser Shellexecute befehl nicht klappt.
Ich hoffe auf Hilfe und würde mich freuen (:
Hier mal mein Code:#include <iostream> #include <string> #include <conio.h> #include <tchar.h> #include <windows.h> #include <direct.h> // for getcwd #include <sstream> using namespace std; int main(int argc, char** args) { string j1 = getenv("TEMP"); string j2 = ("\\IJumper"); string j3 = ("\\Programm.exe"); string j0 (j1 + j2 + j3); cout << j0 << "\n"; //ShellExecute(0, "open", pfad.c_str(), NULL, NULL, SW_SHOWNORMAL); ShellExecute( NULL, _T("open"), j0, _T("/console"), // Programm mit /console ausführen NULL, SW_MINIMIZE); cin.get(); return 0; }Thats not C++0x !
WinAPI -> Windows.h
-
So bessa ?
#include <iostream> #include <string> #include <conio.h> #include <tchar.h> #include <direct.h> // for getcwd #include <sstream> using namespace std; int main(int argc, char** args) { string j1 = getenv("TEMP"); string j2 = ("\\IJumper"); string j3 = ("\\Programm.exe"); string j0 (j1 + j2 + j3); cout << j0 << "\n"; //ShellExecute(0, "open", pfad.c_str(), NULL, NULL, SW_SHOWNORMAL); /* ShellExecute( NULL, _T("open"), j0, _T("/console"), // Programm mit /console ausführen NULL, SW_MINIMIZE); */ cin.get(); return 0; }
-
Ich denke, dass der 3te Parameter beim ShellExecute j0.c_str() lauten sollte.
-
Dieser Thread wurde von Moderator/in SeppJ aus dem Forum C++ (auch C++0x) in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
Klappt leider auch nicht.
#include <iostream> #include <string> #include <conio.h> #include <tchar.h> #include <direct.h> // for getcwd #include <sstream> #include <ostream> #include <windows.h> using namespace std; int main(int argc, char** args) { string j1 = getenv("TEMP"); string j2 = ("\\IJumper"); string j3 = ("\\Programm.exe"); string j0 (j1 + j2 + j3); cout << j0 << "\n"; //ShellExecute(0, "open", pfad.c_str(), NULL, NULL, SW_SHOWNORMAL); ShellExecute( NULL, _T("open"), j0.c_str(), _T("/console"), // Programm mit /console ausführen NULL, SW_MINIMIZE); cin.get(); return 0; }
-
Was wird denn in Zeile 18 ausgegeben?
Vielleicht stimmt der Pfad nicht. Versuche mal über die Funktion GetLastError den Fehler zu ermitteln. Sofern du das Visual Studio benutzt, kannst du auch einfach beim Debuggen im Fenster "Watch" das folgende eintragen: $err,hr
Falls ein Fehler auftrat wird dir die Fehlernummer + Fehlertext im Watch-Fenster ausgegeben.
Watch Window: http://msdn.microsoft.com/en-us/library/aa290869(v=vs.71).aspx
Der Wert wäre interessant.
Ich hoffe, dass du verstanden hast was ich meine, ansonsten suche mal eine Beschreibung zur Funktion GetLastError.
-
Hallo und danke für deine antwort

Ich benutze Visual C++ 2008 Express Edition.
Der Pfad müsste stimmen und schaut so aus.C:\DOKUME1\System31\LOKALE1\Temp\IJumper\Programm.exe
So wird er auch in die Console geschrieben.
-
Ich habs geschafft

Hier mal die Lösung:
#include <tchar.h> #include <direct.h> // for getcwd #include <sstream> #include <ostream> #include <windows.h> using namespace std; int main(int argc, char** args) { string j1 = getenv("TEMP"); string j2 = ("\\IJumper"); string j3 = ("\\Connection.exe"); string j0 = (j1 + j2 + j3); cout << j0 << "\n"; cout << j0.c_str() << "\n"; ShellExecuteA( NULL, "open", j0.c_str(), "22 22", NULL, SW_SHOW ); cin.get(); return 0; }
-
Ok, aber trotzdem solltest du schauen, ob ein anderer Fehler auftrat (muss ja wohl der Fall sein).
Ich habe deinen Code mal um die GetLastError-Funktion erweitert:
#include <iostream> #include <string> #include <conio.h> #include <tchar.h> #include <direct.h> // for getcwd #include <sstream> #include <ostream> #include <windows.h> using namespace std; int main(int argc, char** args) { string j1 = getenv("TEMP"); string j2 = ("\\IJumper"); string j3 = ("\\Programm.exe"); string j0 (j1 + j2 + j3); cout << j0 << "\n"; //ShellExecute(0, "open", pfad.c_str(), NULL, NULL, SW_SHOWNORMAL); ShellExecute( NULL, _T("open"), j0.c_str(), _T("/console"), // Programm mit /console ausführen NULL, SW_MINIMIZE); DWORD dw = GetLastError(); cout << dw << "\n"; cin.get(); return 0; }Was für ein Wert wird ausgegeben?
Schau dann hier: http://msdn.microsoft.com/en-us/library/ms681381(v=vs.85).aspx
um zu sehen, was die Fehlernummer bedeutet.
-
was war denn jetzt falsch ?
-
Hmm, was an deinem Lösungscode führte denn zur Lösung?
Das ShellExecuteA statt ShellExecute kanns nicht sein. SW_SHOW statt SW_MINIZE? Wüsste nicht, warum das eine funktionieren sollte und das andere nicht.
Und der 4 Parameter beim ShellExecute ist imo auch irrelevant.
-
Ups, sollte SW_MINIMIZE heißen.
-
Aus "Programm.exe" wurde "Connection.exe"

-

-
Das Programm.exe ist egal.
Ich habe halt mal weiter gegoogelt und es erst mit ShellExecute dann ShellExecuteW, ShellexecuteA probiert.Also Shellexecute klappte bei mir so.
ShellExecute( NULL, _T("open"), // Öffnen _T("Updater.exe"), // Ist im gleichen Ordner _T("-o"), // Programm Paramter NULL, SW_MINIMIZE); // MinimiertShellexecuteW klappte garnicht.
ShellexecuteA dort ging der Pfad in andere Ordner !
z.B.string j1 = getenv("TEMP"); string j2 = ("\\IJumper"); string j3 = ("\\Connection.exe"); string j0 (j1 + j2 + j3); ShellExecuteA( NULL, "open", j0.c_str(), "22 22", NULL, SW_HIDE ); // MEIN BEISPIEL AUS DEM INTERNET WAR DIESES string url; cout << "Please enter URL: "; getline( cin, url ); cout << url; ShellExecuteA( NULL, "open", url.c_str(), NULL, NULL, SW_SHOW ); //DORT HABE ICH DANN EINFACH DIE STRINGS GEÄNDERT UND ES KLAPPTE MIT DEM PFAD !