C语言/python实现定时关机
1.python
def shutdown():
print('(1)定时关机\n(2)取消定时关机\n(3)立即关机\n(4)关机重启')
b = eval(input('请选择:\n'))
if(b==1):
time = eval(input('请输入定时关机的时间:\n'))
os.system('shutdown -s -t '+str(time*60))
print('设置成功!电脑将在%d分钟后自动关闭。'%time)
elif(b==2):
os.system('shutdown -a')
print('成功取消定时关机设置!')
elif(b==3):
print('确定要立即关机吗?[y/n]')
if(input()=='y'):
os.system('shutdown -s -t 0')
elif(b==4):
print('确定要立即关机重启吗?[y/n]')
if(input()=='y'):
os.system("shutdown -r -t 0")
else:
print('输入有误!')
if __init__ == '__main__':
shutdown()
2.C语言
输入数据即可实现定时关机:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char cmd[20] = "shutdown -s -t ",*temp;
char string[16] = {0};
int time;
printf("输入定时关机时间分钟数:\n");
scanf("%d",&time);
temp = itoa(time*60,string,10);//转换为字符串
system(strcat(cmd,temp));
printf("设置成功!电脑将在%d分钟后定时关机。\n",time);
system("pause");
return 0;
}
以下是取消自动关机的程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
system("shutdown -a");
printf("已取消定时关机!");
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?