0

image error when I try to run an exe file written on a C ++ laptop and a third-party PC, it gives this error

I tried to use Clion and Visual Studio but didn't work. Can you suggest what I'm doing wrong?

the program just changes the file name to a random one

#include <iostream>
#include <Windows.h>
#include <direct.h>
#include <string>

using namespace std;

std::string getFilePath() {
    char path[FILENAME_MAX];
    _getcwd(path, sizeof(path));
    return path;
}

void renamefile() {

    TCHAR szExeFileName[MAX_PATH];
    GetModuleFileName(NULL, szExeFileName, MAX_PATH);
    string path = string(szExeFileName);
    string exe = path.substr(path.find_last_of("\\") + 1, path.size());

    srand(time(0));
    char letters[] = "01V8YutSgDmzEX8pK3gimydac1Sn2eWa9g3z";
    char newname[20];

    int z = rand() % 6 + 6;
    for (int i = 0; i < z; i++)
    {
        char x = letters[rand() % 36];
        newname[i] = x;
    }
    newname[z] = 0x0;
    strcat_s(newname, ".exe\0");
    rename(exe.c_str(), newname);
}

using namespace std;
int main() {
    renamefile();
    cout << "Hello" << endl;
    system("pause");
    return 0;
}
Drew Dormann
  • 59,987
  • 13
  • 123
  • 180

0 Answers0