@@ -1878,7 +1878,7 @@ void handle_crontab(int idx)
18781878 if (to_start)
18791879 {
18801880 config_i_ref[" enabled" ] = true ;
1881- create_process (config_i_ref, ghJob);
1881+ create_process (config_i_ref, ghJob, true );
18821882 log_msg = " method:start started." ;
18831883 // crontab_write_log = true;
18841884 }
@@ -1893,13 +1893,13 @@ void handle_crontab(int idx)
18931893 if (config_i_ref[" enabled" ] && config_i_ref[" running" ] && config_i_ref[" en_job" ])
18941894 {
18951895 disable_enable_menu (config_i_ref, ghJob);
1896- log_msg = " method:kill stopped ." ;
1896+ log_msg = " method:stop killed ." ;
18971897 // crontab_write_log = true;
18981898 }
18991899 if (crontab_method == " restart" )
19001900 {
19011901 config_i_ref[" enabled" ] = true ;
1902- create_process (config_i_ref, ghJob, false );
1902+ create_process (config_i_ref, ghJob, false , true );
19031903 log_msg = " method:restart done." ;
19041904 // crontab_write_log = true;
19051905 }
@@ -1939,12 +1939,12 @@ void handle_crontab(int idx)
19391939 else
19401940 {
19411941 crontab_ref[" enabled" ] = false ;
1942- log_cron_msg = " count limited" ;
1942+ log_cron_msg = " count limited,stopped. " ;
19431943 log_count = -1 ;
19441944 }
19451945 if (json_object_has_member (crontab_ref, " log" ))
19461946 {
1947- crontab_log (config_i_ref , log_time_cur, log_time_next, log_msg, log_cron_msg, log_count);
1947+ crontab_log (crontab_ref , log_time_cur, log_time_next, config_i_ref[ " name " ]. get <std::string>(). c_str (), log_msg, log_cron_msg, log_count, 0 );
19481948 }
19491949 }
19501950 else
@@ -2248,7 +2248,8 @@ void create_process(
22482248 nlohmann::json& jsp, // we may update js
22492249 // int cmd_idx,
22502250 const HANDLE& ghJob,
2251- bool runas_admin
2251+ bool runas_admin,
2252+ bool log_crontab
22522253)
22532254{
22542255 // 必须先用wstring接住,不然作用域会消失
@@ -2442,6 +2443,20 @@ void create_process(
24422443 }
24432444 }
24442445
2446+ if (log_crontab)
2447+ {
2448+ auto & crontab_ref = jsp[" crontab_config" ];
2449+ const size_t buffer_len = 256 ;
2450+ char buffer[buffer_len];
2451+ size_t idx = 0 , len;
2452+ printf_to_bufferA (buffer, buffer_len - idx, idx,
2453+ " si.wShowWindow:%s start_show:%s" ,
2454+ si.wShowWindow == SW_SHOW ? " SW_SHOW" : " SW_HIDE" ,
2455+ start_show ? " true" : " false"
2456+ );
2457+ crontab_log (crontab_ref, 0 , 0 , jsp[" name" ].get <std::string>().c_str (), buffer, " " , 0 , 1 );
2458+ }
2459+
24452460 // https://stackoverflow.com/questions/53208/how-do-i-automatically-destroy-child-processes-in-windows
24462461 // Launch child process - example is notepad.exe
24472462 if (false == require_admin && CreateProcess (NULL , commandLine, NULL , NULL , FALSE , CREATE_NEW_CONSOLE | CREATE_BREAKAWAY_FROM_JOB, NULL , working_directory, &si, &pi))
@@ -2891,7 +2906,7 @@ BOOL IsMyProgramRegisteredForStartup(PCWSTR pszAppName)
28912906 lResult = RegGetValue (hKey, NULL , pszAppName, RRF_RT_REG_SZ, &dwRegType, szPathToExe_reg, &dwSize);
28922907#endif
28932908 fSuccess = (lResult == ERROR_SUCCESS);
2894- }
2909+ }
28952910
28962911 if (fSuccess )
28972912 {
0 commit comments