自动关机程序
#include
#include
#include
#include
#include
#define OK 0
#define FALSE 1
int tm_set(struct time *set_time) {
char ch;
int hour,min,curr_hour,curr_min;
struct time curr_time;
gettime(&curr_time);
system("cls");
printf("set shutdown_os time(for example : 12:00)==");
scanf("%d:%d",&hour,&min);
if(curr_time.ti_hour>=hour&&curr_time.ti_min>=min)
{
system("cls");
printf("Failed!");
sleep(3);
exit(FALSE);
}
set_time->ti_hour=hour;
set_time->ti_min=min;
return OK;
}
int tmcontrol(struct time *set_time)
{
int hour,min;
struct time curr_time;
gettime(&curr_time);
hour=curr_time.ti_hour;
min=curr_time.ti_min;
if(hour==set_time->ti_hour&&min==set_time->ti_min)
{shutdown_os(); return OK;}
else return FALSE;
}
int shutdown_os(void)
{
char *ch="shutdown -s -t 60";
system("cmd /c a.vbs");
sleep(5);
system(ch);
return OK;
}
int set_pwd()
{
char pwd[16];
char data;
int i;
FILE *fp;
clrscr();
printf("set password:");
for(i=0;i<16;i++)
{
if((data=getch())=='\r')
break;
pwd=data;
putchar('*');
}
pwd='\0';
system("cls");
printf("password is: ");
puts(pwd);
getch();
system("cls");
if((fp=fopen("pwd.dat","wb+"))==NULL)
return FALSE;
else { fprintf(fp,"%s",pwd);fclose(fp);}
return OK;
}
int pwd_verify()
{
char ch={0};
char rd[16]={0};
FILE *fp;
if((fp=fopen("pwd.dat","r"))==NULL)
{
set_pwd();
return OK;
}
else
{
fgets(rd,16,fp);
printf("your password:");
scanf("%s",ch);
}
if(strcmp(ch,rd)==0)
return OK;
else {
system("cls");
printf("\n wrong password!");
sleep(3);
return FALSE;
}
}
int hidpro(void)
{
char *srch="cpy.bat";
char *path;
char *hid;
if((path=searchpath(srch))==NULL)
return FALSE;
system(path);
hid="cmdow @ /hid";
system(hid);
return OK;
}
int main()
{
struct time *set_time;
int work=1;
system("cls");
if(pwd_verify()==OK)
tm_set(set_time);
else return FALSE;
if(hidpro()==OK)
{
while(work==1)
{
if(tmcontrol(set_time)==OK)
break;
sleep(30);
}
}
else
{
printf("File lost!");
return FALSE;
}
return OK;
}