ShellExecute mit String ?



  • 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); // Minimiert
    

    ShellexecuteW 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 !
    

Anmelden zum Antworten