#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <fstream>
#include <random>
//for windows. this is not license for any person.
bool CreateText(const std::string& Name, const std::string& Text) {
std::ofstream ofs(Name);
if (ofs.is_open()) { ofs << Text << std::endl; }
return ofs.is_open();
}
std::string MakeTempName() {
std::random_device rd;
return std::to_string(std::time(nullptr)) + "_" + std::to_string(rd());
}
int main() {
std::string Tag = "ODaI_0xdeadbeef.";
std::time_t T = std::time(nullptr);
std::tm TM = *std::localtime(&T);
int PodS = 1;
std::string SH = std::to_string((TM.tm_hour + (TM.tm_min + PodS) / 60) % 24);
std::string SM = std::to_string((TM.tm_min + PodS) % 60);
if (SH.size() == 1) { SH = '0' + SH; };
if (SM.size() == 1) { SM = '0' + SM; };
int PodE = PodS + 11;
std::string EH = std::to_string((TM.tm_hour + (TM.tm_min + PodE) / 60) % 24);
std::string EM = std::to_string((TM.tm_min + PodE) % 60);
if (EH.size() == 1) { EH = '0' + EH; };
if (EM.size() == 1) { EM = '0' + EM; };
std::string BasePath = "c:\\Testdel\\";
std::string Name = MakeTempName();
std::string Ext = ".tmp.bat";
std::string Task = BasePath + Name + Ext;
std::string Message0 = "echo off \n";
std::string Message1 = "cls \n";
std::string Message2 = "echo 「このプログラムが起動するのは一度きりである。実行ののち、消去される。」\n";
//std::string Command = "echo rm -f " + av[0]+"\n"+;
std::string Command = "dir\n";
std::string Pause = "Pause\n";
std::string KillTask1 = "schtasks /delete /tn " + Tag + " /f \n";
std::string KillTask2 = "del " + Task + "\n";
std::string Schedule = "schtasks /create /tn \"" + Tag + "\" /tr \"" + Task + "\" /sc once /st " + SH + ':' + SM + " /et " + EH + ':' + EM + " /z";
std::cout << '>' << Schedule << std::endl;
bool F = CreateText(Task,Message0+ Message1+ Message2 +Pause+ Command + KillTask1 + KillTask2);
std::system(Schedule.data());
if (!F) {
std::system(KillTask1.data());
}
return 0;
}