Ausgeführte Datei kopieren zur Laufzeit



  • Ich versuche die momentan ausgeführte Datei in einen
    anderen Ordner zu kopieren, stoße dabei jedoch auf Probleme.
    Hole ich den Pfad für pFrom über GetCommandLine, dann wird
    nicht kopiert un dich erhalte die Meldung dass vom Quellpfad
    nicht gelesen werden kann.
    Gebe ich den Pfad direkt an geht es allerdings...

    CString strPath = GetCommandLine();
    //strPath="C:\\test\\exepfad.exe";  //das geht
    strPath+='\0';
    //MessageBox(strPath);
    
    SHFILEOPSTRUCT foCopy; 
    
    foCopy.hwnd                  = NULL;  
    foCopy.wFunc                 = FO_COPY; 
    foCopy.pFrom                 = strPath; 
    foCopy.pTo                   = "c:\\"; 
    foCopy.fFlags                = FOF_NOCONFIRMATION; 
    foCopy.fAnyOperationsAborted = FALSE;  
    foCopy.hNameMappings         = NULL; 
    foCopy.lpszProgressTitle     = NULL;  
    
    if(SHFileOperation(&foCopy) == 0) { 
    
    } 
    else { 
    
    }
    


  • Hi,

    hole doch den Pfad mit dem

    DWORD GetModuleFileName(
    HMODULE hModule, // handle to module to find filename for
    LPTSTR lpFilename, // pointer to buffer to receive module path
    DWORD nSize // size of buffer, in characters
    );

    z.B. GetModuleFileName( NULL, buf, sizeof(buf));

    und dann mit CopyFile() weiter...

    Grüß
    Peter


Anmelden zum Antworten