I'm creating C++ code that will create some .bat
file and store it in the %appdata%
folder. I've successfully to created the file, but still fail to create the folder and execute it.
Below is my simple code, it doesn't look simple but it works to create .bat
file in %appdata%
, maybe someone can help me to find the simple one.
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <sstream>
#include <string>
#include <windows.h>
#include <direct.h>
int main(int argc, char **argv) {
using namespace std;
std::ofstream aaa;
ostringstream aaa;
aaa.open(aaa1.str());
aaa1 << getenv("appdata") << "/"
<< "test.bat";
aaa.open(aaa1.str());
Updater << "@echo on" << endl;
Updater << "echo \"on\"" << endl;
return 0;
}
The code successfully creates the .bat
file in %appdata%
, but I need to store in new folder in %appdata%
, say New Folder
, and then execute the .bat
file.