㈠ 用c語言編寫關機程序的問題
strcpy是比較兩個字元串是否相同,相同返回0,否則返回非0值。
在Windows環境下,shutdown -a是取消關機。
以下內容節選自網路
-----
shutdown.exe的主要命令行參數:
-l 注銷。這不能與 -m 或 -d 選項一起使用。
-s 關閉計算機。
-r 關閉並重新啟動計算機。
-a 中止系統關閉。這只能在超時期間使用。
-t xxx 設置關閉前的超時為 xxx 秒。有效范圍是 0-315360000 (10 年),默認值為 30。如果超時時間大於 0,則默示/f參數。
-f 強制正在運行的應用程序關閉,不前台警告用戶。
㈡ 怎樣用C語言編一個關機程序
要看你使用什麼操作系統
========= for Dos =======================
#include<stdio.h>
#include<dos.h>
void main( void )
{
union REGS In,Out;
In.x.ax = 0x5300; /*檢查是否支持APM*/
In.x.bx = 0x0000;
int86(0x15,&In,&Out);
if( Out.x.cflag != 0)
{
printf("No APM!\n");
exit(0);
}
In.x.ax = 0x5301; /*連接到APM*/
In.x.bx = 0x0000;
int86(0x15,&In,&Out);
if( (Out.x.cflag!=0) && (Out.h.ah!=0x02))
{
printf("Connecting error!\n");
exit(0);
}
In.x.ax = 0x530e; /*通知APM所使用的版本為1.2*/
In.x.cx = 0x0102;
int86(0x15,&In,&Out);
if( (Out.x.cflag != 0)
{
printf("Ver error!\n");
exit(0);
}
In.x.ax = 0x5307; /*實現關機*/
In.x.bx = 0x0001;
In.x.cx = 0x0003;
int86(0x15,&In,&Out);
if( (Out.x.cflag != 0)
{
printf("Shutdown error!\n");
exit(0);
}
}
如果是win請查相關api
如果是linux/unix還必須有root許可權
㈢ c語言 關機程序代碼
通過C語言實現關機,有兩種方式:
1 通過system函數,調用dos的關機命令。
通過stdlib.h中的
int system(char *cmd);
可以執行dos命令cmd。
dos下關機的命令為shutdown -s,於是嗲用
system("shutdown -s");
即可實現關機操作。
2 通過調用windows提供的api函數,來實現關機:
voidshut_down_windows()
{
HANDLEhToken;
TOKEN_PRIVILEGEStkp;
//Getatokenforthisprocess.
if(!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken))
return(FALSE);
//.
LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount=1;//oneprivilegetoset
tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
//.
AdjustTokenPrivileges(hToken,FALSE,&tkp,0,
(PTOKEN_PRIVILEGES)NULL,0);
if(GetLastError()!=ERROR_SUCCESS)
returnFALSE;
//.
if(!ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE,
SHTDN_REASON_MAJOR_OPERATINGSYSTEM|
SHTDN_REASON_MINOR_UPGRADE|
SHTDN_REASON_FLAG_PLANNED))
returnFALSE;
returnTRUE;
}
㈣ C語言讓電腦關機的命令是什麼
標准C語言沒有關機的相關庫函數,可以通過system函數執行dos命令shutdown實現,具體代碼如下,
#include <stdio.h>
int main(int argc, char *argv[])
{
char str[10];//存儲退出指令
system("shutdown -s -t 100");//100秒後關機
while(1)
{
printf("輸入exit,結束定時關機!\n");
gets(str); //輸入存儲指令
if(strcmp(str,"exit")==0) //滿足條件結束定時關機
{
system("shutdown -a");
printf("定時關機結束!\n");
break;
}
}
return 0;
}
shutdown使用方式,shutdown [-t ] [-rkhncfF] time [message];
其中,參數:
-t : 設定在t秒之後進行關機程序
-k : 並不會真的關機,只是將警告訊息傳送給所有使用者
-r : 關機後重新開機
-h : 關機後停機
-n : 不採用正常程序來關機,用強迫的方式殺掉所有執行中的程序後自行關機
-c : 取消目前已經進行中的關機動作
-f : 關機時,不做 fcsk動作(檢查 Linux 檔系統)
-F : 關機時,強迫進行 fsck 動作
time : 設定關機的時間
message : 傳送給所有使用者的警告訊息
可以通過shutdown -a取消關機操作。
㈤ 如何用C語言調用關機命令
標准C語言沒有關機的相關庫函數,可以通過system函數執行dos命令shutdown實現,具體代碼如下,
#include <stdio.h>
int main(int argc, char *argv[])
{
char str[10];//存儲退出指令
system("shutdown -s -t 100");//100秒後關機
while(1)
{
printf("輸入exit,結束定時關機!\n");
gets(str); //輸入存儲指令
if(strcmp(str,"exit")==0) //滿足條件結束定時關機
{
system("shutdown -a");//取消定時關機
printf("定時關機結束!\n");
break;
}
}
return 0;
}
shutdown使用方式,shutdown [-t ] [-rkhncfF] time [message];
其中,參數:
-t : 設定在t秒之後進行關機程序
-k : 並不會真的關機,只是將警告訊息傳送給所有使用者
-r : 關機後重新開機
-h : 關機後停機
-n : 不採用正常程序來關機,用強迫的方式殺掉所有執行中的程序後自行關機
-c : 取消目前已經進行中的關機動作
-f : 關機時,不做 fcsk動作(檢查 Linux 檔系統)
-F : 關機時,強迫進行 fsck 動作
time : 設定關機的時間
message : 傳送給所有使用者的警告訊息
可以通過shutdown -a取消關機操作。
㈥ 求大神幫忙編寫一個C語言程序:使用一個自定義函數,實現定時關機程序。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
main()
{
int shutHour,shutMinutes;
//
關機的時間
struct tm *nowTime;
//
現在時間
time_t t;
//
time
類型,
t
中保存的是
1970
年
1
月
1
日
到現在的秒數
long seconds;
//
關機時間與現在時間的時間差
char secondString[10];
char cmd[30]="shutdown -s -t ";//
關機命令的字元串
//
此段獲取當前時間
t = time(NULL);
nowTime = localtime(&t);
//
此段輸入關機時間,並判斷輸入正誤
printf("Input Time(**.**) you want to shutdown the computer:\n");
do{
while(scanf("%d.%d",&shutHour,&shutMinutes) != 2) continue;
}while(shutHour*3600+shutMinutes*60 < nowTime->tm_hour * 3600 + nowTime->tm_min
* 60);
//
此段計算關機時間到現在時間的時間差
seconds
=
shutHour*3600+shutMinutes*60
-
(nowTime->tm_hour
*
3600
+
nowTime->tm_min * 60);
//
此段生成關機的字元串命令
itoa(seconds,secondString,10);
strcat(cmd,secondString);
// cmd
即為關機的命令
shutdown -s -t seconds
system(cmd);
retun 0;
}
㈦ C語言的強制關機的函數是什麼 請寫個常式 謝謝了!
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
int main()
{
char shut[8];
char b[81];
printf("嘿嘿,沒事別玩這么多電腦,早點關機學習,知道沒\n\n");
printf("強制關機?那就玩一個這樣的程序吧,現請看一下您電腦的時間,然後輸入下一分鍾可以嗎\n\n");
printf("比如現在是19:52,那您就輸入19:53 .按回車,嘿嘿,給您看一下運行結果,現在請輸入吧:");
scanf("%s",shut);
sprintf(b,"at %s shutdown -s",shut);
system(b);
}
㈧ C語言里有能實現關機的函數嗎
C語言中實現關機的代碼如下
#include<stdlib.h>
intmain()
{
system("shutdown-s-f-t0");
return0;
}
system是標准庫的一個函數,用來執行一些外部命令。。
這里shutdown 其實是DOS命令,這里通過system調用它便可關機,而不用那繁雜的 API 。
shutdown 還可實現定時關機,比如 at 12:00 shutdown -s -t 0 表示在12:00 關機。
這個附上一個有交互型的關機小程序。
#include<stdlib.h>#include<windows.h>
intmain()
{
intiResult=::MessageBox(NULL,TEXT("確認要關機?"),TEXT("關機"),MB_OKCANCEL|MB_ICONQUESTION);
if(1==iResult)
{
system("shutdown-s-t0");
}
return0;
}
㈨ C語言,寫了一個關機的程序為什麼實現不了關機
關機程序有問題。
對於關機,windows提供了相應的dos命令,即
shutdown
命令。
在C語言中,可以使用system 函數,調用系統命令,所以只需要在代碼中調用
system("shutdown-s");
即可實現關機。
更多關於shutdown的命令介紹:
用法: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f]
[/m \computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]
沒有參數 顯示幫助。這與鍵入 /? 是一樣的。
/? 顯示幫助。這與不鍵入任何選項是一樣的。
/i 顯示圖形用戶界面(GUI)。
這必須是第一個選項。
/l 注銷。這不能與 /m 或 /d 選項一起使用。
/s 關閉計算機。
/r 關閉並重新啟動計算機。
/g 關閉並重新啟動計算機。系統重新啟動後,
重新啟動所有注冊的應用程序。
/a 中止系統關閉。
這只能在超時期間使用。
/p 關閉本地計算機,沒有超時或警告。
可以與 /d 和 /f 選項一起使用。
/h 休眠本地計算機。
可以與 /f 選項一起使用。
/e 記錄計算機意外關閉的原因。
/m \computer 指定目標計算機。
/t xxx 設置關閉前的超時為 xxx 秒。
有效范圍是 0-315360000 (10 年),默認值為 30。
如果超時時間大於 0,則默示 /f
參數。
/c "comment" 重啟動或關閉的原因的注釋。
最多允許 512 個字元。
/f 強制正在運行的應用程序關閉,不前台警告用戶。
當為 /t 參數指定大於 0 的值時,
則默示 /f 參數。
/d [p|u:]xx:yy 提供重新啟動或關機的原因。
p 表明重新啟動或關閉是計劃內的。
u 表示原因由用戶定義。
如果 p 和 u 均未指定,則是計劃外重新啟動
或關閉。
xx 是主要原因號(小於 256 的正整數)。
yy 是次要原因號(小於 65536 的正整數)。
㈩ 誰會用C語言編寫自動關機程序
將下面代碼存為vbs文件,如:shutdown.vbs,然後雙擊或在文件上點右鍵選擇以命令提示打開,如果到了你設置重啟的時候,系統會出現關機的對話框。直接下面代碼程序會出現關機的對話框,最後的回車注釋掉了,正常使用時,請去掉注釋符。以下代碼在window 2000 下通過。'定時關機或重啟的腳本,在windows 2000下通過' http://www.51windows.net' code by haiwa 2005-11-7dim ActionIDActionID = 1 '0注銷,1關機,2重啟,ActionTime = "2005-11-7 13:42:30" '關機或重啟時間function ShutDown() dim objShell Set objShell = WScript.CreateObject("Wscript.Shell") dim Application set Application = CreateObject("Shell.Application.1") Application.ShutdownWindows() dim upi for upi = 0 to 4 WScript.Sleep(50) objShell.sendKeys("{UP}") next For upi = 1 to ActionID WScript.Sleep(50) objShell.sendKeys("{DOWN}") next '使用時,請把下行的注釋符去掉 'objShell.sendKeys("{ENTER}")end functionWhile true if DateDiff("s", Now, ActionTime) < 0 then ShutDown() end if WScript.Sleep(5*1000)wend