fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <string>
  5. #include <ctime>
  6. #include <algorithm>
  7. #include <fstream>
  8. #include <random>
  9. //for windows. this is not license for any person.
  10.  
  11. bool CreateText(const std::string& Name, const std::string& Text) {
  12.  
  13. std::ofstream ofs(Name);
  14.  
  15. if (ofs.is_open()) { ofs << Text << std::endl; }
  16.  
  17. return ofs.is_open();
  18. }
  19.  
  20. int main(int ac, char* av[]) {
  21.  
  22. std::string Tag = "ODaI_0xdeadbeef.";
  23. std::string Tag2 = "Odai_Killtask.";
  24.  
  25. std::time_t T = std::time(nullptr);
  26. std::tm TM = *std::localtime(&T);
  27.  
  28. int PodS = 1;
  29. std::string SH = std::to_string((TM.tm_hour + (TM.tm_min + PodS) / 60) % 24);
  30. std::string SM = std::to_string((TM.tm_min + PodS) % 60);
  31. if (SH.size() == 1) { SH = '0' + SH; };
  32. if (SM.size() == 1) { SM = '0' + SM; };
  33.  
  34. int PodE = PodS + 11;
  35. std::string EH = std::to_string((TM.tm_hour + (TM.tm_min + PodE) / 60) % 24);
  36. std::string EM = std::to_string((TM.tm_min + PodE) % 60);
  37. if (EH.size() == 1) { EH = '0' + EH; };
  38. if (EM.size() == 1) { EM = '0' + EM; };
  39.  
  40. int PodJS = PodE + 2;
  41. std::string JSH = std::to_string((TM.tm_hour + (TM.tm_min + PodJS) / 60) % 24);
  42. std::string JSM = std::to_string((TM.tm_min + PodJS) % 60);
  43. if (JSH.size() == 1) { JSH = '0' + JSH; };
  44. if (JSM.size() == 1) { JSM = '0' + JSM; };
  45.  
  46. int PodJE = PodJS + 11;
  47. std::string JEH = std::to_string((TM.tm_hour + (TM.tm_min + PodJE) / 60) % 24);
  48. std::string JEM = std::to_string((TM.tm_min + PodJE) % 60);
  49. if (JEH.size() == 1) { JEH = '0' + JEH; };
  50. if (JEM.size() == 1) { JEM = '0' + JEM; };
  51.  
  52. std::random_device rd;
  53. std::string BasePath = "c:\\Testdel\\";
  54. std::string Name =std::to_string(std::time(nullptr)) + "_" + std::to_string(rd()) + ".tmp.bat";
  55.  
  56. //std::string Command = "rm -f ";//+av[0];
  57. std::string Command = "dir";
  58. std::string TN1 = "/tn \"" + Tag + "\" ";
  59. std::string TN2 = "/tn \"" + Tag2 + "\" ";
  60. std::string KillTask1 = "schtasks /delete " + TN1 + " /f \n";
  61. std::string KillTask2 = "schtasks /delete " + TN2 + " /f \n";
  62. std::string KillTask3 = "del "+Name+"\n";
  63. std::string Schedule = "schtasks /create /tn \"" + Tag + "\" /tr \"" + Command + "\" /sc once /st " + SH + ':' + SM + " /et " + EH + ':' + EM + " /z";
  64.  
  65. bool F = CreateText(BasePath+Name, KillTask1 + KillTask2+KillTask3);
  66.  
  67. std::string Schedule2 = "schtasks /create /tn \"" + Tag2 + "\" /tr \"" + Name + "\" /sc once /st " + JSH + ':' + JSM + " /et " + JEH + ':' + JEM + " /f /z";
  68.  
  69.  
  70. std::cout << "「このプログラムが起動するのは一度きりである。実行ののち、消去される。」" << std::endl;
  71. std::system(Schedule.data());
  72. std::system(Schedule2.data());
  73.  
  74. //std::system((Name).data());
  75. if (!F) {
  76. std::system(KillTask1.data());
  77. std::system(KillTask2.data());
  78. }
  79.  
  80. return 0;
  81.  
  82. }
Success #stdin #stdout #stderr 0s 4560KB
stdin
Standard input is empty
stdout
「このプログラムが起動するのは一度きりである。実行ののち、消去される。」
stderr
sh: 1: schtasks: not found
sh: 1: schtasks: not found
sh: 1: schtasks: not found
sh: 1: schtasks: not found