fork(2) 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. std::string MakeTempName() {
  21. std::random_device rd;
  22. return std::to_string(std::time(nullptr)) + "_" + std::to_string(rd());
  23. }
  24.  
  25. int main() {
  26. std::string Tag = "ODaI_0xdeadbeef.";
  27.  
  28. std::time_t T = std::time(nullptr);
  29. std::tm TM = *std::localtime(&T);
  30.  
  31. int PodS = 1;
  32. std::string SH = std::to_string((TM.tm_hour + (TM.tm_min + PodS) / 60) % 24);
  33. std::string SM = std::to_string((TM.tm_min + PodS) % 60);
  34. if (SH.size() == 1) { SH = '0' + SH; };
  35. if (SM.size() == 1) { SM = '0' + SM; };
  36.  
  37. int PodE = PodS + 11;
  38. std::string EH = std::to_string((TM.tm_hour + (TM.tm_min + PodE) / 60) % 24);
  39. std::string EM = std::to_string((TM.tm_min + PodE) % 60);
  40. if (EH.size() == 1) { EH = '0' + EH; };
  41. if (EM.size() == 1) { EM = '0' + EM; };
  42.  
  43. std::string BasePath = "c:\\Testdel\\";
  44. std::string Name = MakeTempName();
  45. std::string Ext = ".tmp.bat";
  46. std::string Task = BasePath + Name + Ext;
  47. std::string Message0 = "echo off \n";
  48. std::string Message1 = "cls \n";
  49. std::string Message2 = "echo 「このプログラムが起動するのは一度きりである。実行ののち、消去される。」\n";
  50. //std::string Command = "echo rm -f " + av[0]+"\n"+;
  51. std::string Command = "dir\n";
  52. std::string Pause = "Pause\n";
  53. std::string KillTask1 = "schtasks /delete /tn " + Tag + " /f \n";
  54. std::string KillTask2 = "del " + Task + "\n";
  55.  
  56. std::string Schedule = "schtasks /create /tn \"" + Tag + "\" /tr \"" + Task + "\" /sc once /st " + SH + ':' + SM + " /et " + EH + ':' + EM + " /z";
  57.  
  58. std::cout << '>' << Schedule << std::endl;
  59.  
  60. bool F = CreateText(Task,Message0+ Message1+ Message2 +Pause+ Command + KillTask1 + KillTask2);
  61. std::system(Schedule.data());
  62. if (!F) {
  63. std::system(KillTask1.data());
  64. }
  65.  
  66.  
  67. return 0;
  68. }
  69.  
  70.  
  71.  
Success #stdin #stdout #stderr 0s 4396KB
stdin
Standard input is empty
stdout
>schtasks /create /tn "ODaI_0xdeadbeef." /tr "c:\Testdel\1570471107_279910698.tmp.bat" /sc once /st 17:59 /et 18:10 /z
stderr
sh: 1: schtasks: not found
sh: 1: schtasks: not found