#include "stdio.h"#include "string.h"#include "time.h"#include "stdlib.h" int main( void ){ char *strTime; time_t myTime; // long型时间 bool isDel; time( &myTime ); // 取得时间 strTime = ctime( &myTime ); // 转换为字符串 printf( "%s", strTime ); // 显示时间 isDel = false; while( !isDel ) // 程序一直运行,直到删除了文件才结束次程序。{ /* 如果为18:00点则删除文件 */ if ( ( strTime[11] == '1' ) && ( strTime[12] == '8' ) && ( strTime[14] == '0' ) && ( strTime[15] == '0' ) ) { system( "type aaa.txt" ); // 显示文件的内容 system( "del aaa.txt" ); // 删除文件 } } system( "pause" ); return 0;} 如果想要次程序在每次启动计算机后自动执行,则只要HKLM的Run里添加一个字符串键值就可以了。 键值为:删除文件的程序的路径。 假如次程序保存名为TimingDel.exe,则将键值设置为:E:\App Exap\C C++\TimingDel\Debug\TimingDel.exe (这是我的电脑上的路径)。 这样每次启动计算机后他会自动执行。。

评论