日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

断网,启用网络,关机的实现。

發布時間:2023/11/27 生活经验 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 断网,启用网络,关机的实现。 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

windows 下實現 shutdown_two.c 此為第三版

    //  我需要一個斷開網絡,啟用網絡,定時發送郵件后關機的功能,其中定時發送郵件功能是郵件客戶端完成;原來的工具是用bat實現的,后來給BAT內容放到C中,延時部分用的還是 choice ,因此需要手工輸入延時時間。//  后來想做個自動計算時間的方法,后來發現sleep用這個功能,遂寫了這個功能。說個小插曲,這是第三版,第一版是bat文件,第二版是shutdown.c文件,它生成shutdown.exe文件,注意這個文件名,因為第二版是需要輸入當前時間和定時啟用網絡時間的差值來決定延時多久;
//      這版shutdown_two.c生成的文件shutdown_two.exe和shutdown.exe在同一目錄下,執行的時候到shutdown命令時,會先在當前目錄下先尋找有無shutdown命令并調用,所以每次執行shutdown_two.exe時都會在關機時提示Please input the hour:,所以一直無法關機。#include <stdio.h>
#include <string.h> 
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{int hour, sec;int n, m;time_t a;time(&a);       // a值為時間戳printf("a:%lld\n", a);printf("the time is %s", ctime(&a));   // 細分時間格式struct tm t;          // 定義成員 ttime_t bell;          // 時間類型
//      char str[80];         t.tm_sec=0;t.tm_min=0;t.tm_hour=10;t.tm_mday=info->tm_mday;  //通過info->tm_mday獲得月中某天,info為已獲得的系統時間。t.tm_mon=info->tm_mon;    //通過info->tm_mon獲得月份t.tm_year=info->tm_year;  // 通過info->tm_year獲得年份bell = mktime(&t);printf("the bell time is %lld\n", bell);hour = ((long int)difftime(bell,a)) / 3600;sec = ((long int)difftime(bell,a)) % 3600;printf("The sleep time %d hour, %d sec\n", hour, sec);printf("chazhi is %ld\n",(long int)difftime(bell,a));system("netsh interface set interface name=\"WIFI\" admin=disabled");for (n = 0; n < (long int)difftime(bell,a) ; ++n){sleep(1);}system("netsh interface set interface name=\"WIFI\" admin=enabled");for (m = 0; m < (long int)difftime(bell,a) ; ++m){sleep(1);}system("shutdown -f -s -t 0");    // 文件名起的不要和你調用的系統命令重名// 程序會先在本目錄下找是否有同名的exe文件// 有就會調用,這樣就無法執行系統命令return 0;
}下面是第二版#  第二版
#include <stdio.h>
#include <stdlib.h>
int main(void)
{int min, hour, n;printf("Please input the hour: ");scanf("%d", &hour);printf("Please input the minute: ");scanf("%d", &min);system("netsh interface set interface name=\"WIFI\" admin=disabled");for (n = 0; n < hour; ++n)system("choice /c k /n /t 3600 /d k 1>nul");char string[100];min *= 60;sprintf(string, "choice /c k /n /t %d  /d k 1>nul", min);system(string);system("netsh interface set interface name=\"WIFI\" admin=enabled");system("choice /c k /n /t 600 /d k 1>nul");system("shutdown -f -s -t 20");return 0;
}

轉載于:https://www.cnblogs.com/EisNULL/p/10838496.html

總結

以上是生活随笔為你收集整理的断网,启用网络,关机的实现。的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。