Переместите запущенный EXE на новое место, не ожидая перезагрузки - PullRequest
0 голосов
/ 22 мая 2019

Я пытаюсь переместить запущенный EXE, но это дает access denied because of running state. Я мог бы использовать MoveFileEx(MOVEFILE_DELAY_UNTIL_REBOOT), но это действует только после перезагрузки.

Есть ли способ сделать это, не дожидаясь перезагрузки?

int _tmain(int argc, _TCHAR* argv[]){
    WCHAR szFilepath[MAX_PATH];
    std::wstring wFilepath;
    std::wstring wFilename;
    std::wstring wDestpath;

    /* Get the current executable's full path */
    wFilepath = std::wstring(szFilepath, GetModuleFileNameW(NULL, szFilepath, MAX_PATH));
    std::wcout << L"filepath: " << wFilepath << std::endl;

    /* Extract just the name */
    wFilename = wFilepath.substr(wFilepath.find_last_of(L"\\/") + 1);
    std::wcout << L"filename: " << wFilename << std::endl;

    /* Set the destination folder path and file name */
    wDestpath = L"D:\\" + wFilename;
    std::wcout << L"dest path: " << wDestpath << std::endl;

    // copys the file of your '.exe'

    if (!CopyFileW(wFilepath.c_str(), wDestpath.c_str(), FALSE)) {
        std::wcout << L"couldnt copy the file";
    }
    else {
        std::wcout << L"copied";
    }
    return 0;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...