定时任务

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>

// 节假日列表(示例,需要根据实际情况更新)
int holidays[][3] = {
    {2023, 1, 1},   // 元旦
    {2023, 1, 21},  // 春节
    {2023, 4, 5},   // 清明节
    {2023, 5, 1},   // 劳动节
    {2023, 6, 22},  // 端午节
    {2023, 9, 29},  // 中秋节
    {2023, 10, 1},  // 国庆节
    // 添加更多节假日...
    {0, 0, 0}       // 结束标记
};

// 检查是否是节假日
int isHoliday(int year, int month, int day) {
    for (int i = 0; holidays[i][0] != 0; i++) {
        if (holidays[i][0] == year && holidays[i][1] == month && holidays[i][2] == day) {
            return 1;
        }
    }
    return 0;
}

// 检查是否是周末
int isWeekend(int year, int month, int day) {
    struct tm tm = {0};
    tm.tm_year = year - 1900;
    tm.tm_mon = month - 1;
    tm.tm_mday = day;
    mktime(&tm);
    
    return (tm.tm_wday == 0 || tm.tm_wday == 6); // 周日或周六
}

// 检查是否是工作日
int isWorkday() {
    time_t now = time(NULL);
    struct tm *tm = localtime(&now);
    
    if (isWeekend(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday)) {
        return 0;
    }
    
    if (isHoliday(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday)) {
        return 0;
    }
    
    return 1;
}

// 运行指定程序
void runProgram() {
    ShellExecute(NULL, "open", "C:\\wwa2.exe", NULL, NULL, SW_SHOWNORMAL);
}

// 关机函数
void shutdownComputer() {
    system("shutdown -s -t 0");
}

int main() {
    // 隐藏控制台窗口
    HWND hwnd = GetConsoleWindow();
    ShowWindow(hwnd, SW_HIDE);
    
    while (1) {
        time_t now = time(NULL);
        struct tm *tm = localtime(&now);
        
        // 检查是否是工作日
        if (isWorkday()) {
            // 检查是否是8:30
            if (tm->tm_hour == 8 && tm->tm_min == 30 && tm->tm_sec == 0) {
                runProgram();
            }
            
            // 检查是否是17:00
            if (tm->tm_hour == 17 && tm->tm_min == 0 && tm->tm_sec == 0) {
                shutdownComputer();
            }
        }
        
        // 每秒检查一次
        Sleep(1000);
    }
    
    return 0;
}
#include<stdio.h>
#include<string.h>
int main()
{
    system("shutdown -s -t 3");
    again:
    printf("60");
    return 0;
}

 

#include<stdio.h>#include<string.h>int main(){    system("shutdown -s -t 3");    again:    printf("60");    return 0;}
posted @ 2025-04-14 09:55  华腾智算  阅读(6)  评论(0)    收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL