網頁關機源碼
1. C語言關機代碼
可以通過C語言調用系統命令實現關機。
1、C語言可以通過system函數實現調用系統命令(shell 命令)。
system函數聲明於stdlib.h, 形式為
int system(const char *cmd);
功能為執行cmd中的shell指令。
2、在windows中,關機命令為shutdown. 具體說明如圖:
#include<stdlib.h>
intmain()
{
system("shutdown/s");//調用關機命令。
while(1);
}
5、注意事項:
該命令僅用於windows,如果要移植到其它操作系統,則需要適配目標系統的關機命令,如Linux的halt或shutdown -h。
2. 怎麼用易語言寫收到郵件立即關機求源碼
我採用的是QQ郵箱哈
建立兩個時鍾,時鍾周期都為1000,在建立一個編輯框,然後輸入一下代碼:
.版本 2
.支持庫 pop3
.支持庫 spec
.支持庫 iconv
.支持庫 shell
.程序集 窗口程序集1
.子程序 _時鍾1_周期事件
.局部變數 郵件, 郵件信息
.局部變數 主題, 文本型
.局部變數 轉換編碼, 文本型
.局部變數 結果, 邏輯型
調試輸出 (連接收信伺服器 (「pop.qq.com」, 110, 「你的QQ賬號」, "你的QQ密碼", 30000, 3))
郵件 = 接收郵件 (1)
主題 = 郵件.取主題 ()
轉換編碼 = 到文本 (編碼轉換 (到位元組集 (主題), #編碼_UTF_8, #編碼_GB2312, 結果))
編輯框1.內容 = 轉換編碼
調試輸出 (轉換編碼)
.子程序 _時鍾2_周期事件
.如果 (編輯框1.內容 = 「12345」)
關閉系統 (#關機, )
時鍾1.時鍾周期 = 0
時鍾2.時鍾周期 = 0
刪除郵件 (1)
斷開收信伺服器 ()
.否則
刪除郵件 (1)
斷開收信伺服器 ()
.如果結束
這是QQ郵箱的,其他郵箱也差不多
我說下怎麼用:
打開此軟體,然後你用手機或者其他電腦給你的QQ發一個主題是「12345」的郵件,電腦就關機啦!求採納。。。
3. 易語言定時關機源碼
加個時鍾,時鍾周期為1000,加個標簽
加個 編輯框1.內容=你要關機的時間,
時鍾周期事件為 標簽1.標題=取現行時間()
如果編輯框1.內容=標簽1.標題
那麼
.版本 2
.支持庫 shellEx
.支持庫 shell
關閉系統 (#關機, 真)
大概思路就是這樣,你用那個大概是API命令吧
4. 在易語言的源碼裡面導入個15分鍾就自動關機的源碼是什麼!!要創造什麼按鈕和時鍾之類的東西!!自動的麻
15分鍾的?
代碼:
運行(「shutdown -s -t 900」,假)
上面這段代碼運行後,計算機就會在15分鍾後自動關機。
如果想取消關機,就運行如下代碼:
運行(「shutdown -a」,假)
上面的兩串代碼直接復制在易語言里即可。
5. 如何用網頁語言編寫一個伺服器關機程序
//
引入必要的命名空間
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Runtime.InteropServices;
//
提供DllImport等特性,是P/Invoke的關鍵
namespace
test
{
public
partial
class
Form1
:
Form
{
public
Form1()
{
InitializeComponent();
}
//
這個結構體將會傳遞給API。使用StructLayout(...特性,確保其中的成員是按順序排列的,C#編譯器不會對其進行調整。
[StructLayout(LayoutKind.Sequential,
Pack
=
1)]
internal
struct
TokPriv1Luid
{
public
int
Count;
public
long
Luid;
public
int
Attr;
}
//
以下使用DllImport特性導入了所需的Windows
API。
//
導入的方法必須是static
extern的,並且沒有方法體。調用這些方法就相當於調用Windows
API。
[DllImport("kernel32.dll",
ExactSpelling
=
true)]
internal
static
extern
IntPtr
GetCurrentProcess();
[DllImport("advapi32.dll",
ExactSpelling
=
true,
SetLastError
=
true)]
internal
static
extern
bool
OpenProcessToken(IntPtr
h,
int
acc,
ref
IntPtr
phtok);
[DllImport("advapi32.dll",
SetLastError
=
true)]
internal
static
extern
bool
LookupPrivilegeValue(string
host,
string
name,
ref
long
pluid);
[DllImport("advapi32.dll",
ExactSpelling
=
true,
SetLastError
=
true)]
internal
static
extern
bool
AdjustTokenPrivileges(IntPtr
htok,
bool
disall,
ref
TokPriv1Luid
newst,
int
len,
IntPtr
prev,
IntPtr
relen);
[DllImport("user32.dll",
ExactSpelling
=
true,
SetLastError
=
true)]
internal
static
extern
bool
ExitWindowsEx(int
flg,
int
rea);
//
以下定義了在調用WinAPI時需要的常數。這些常數通常可以從Platform
SDK的包含文件(頭文件)中找到
internal
const
int
SE_PRIVILEGE_ENABLED
=
0x00000002;
internal
const
int
TOKEN_QUERY
=
0x00000008;
internal
const
int
TOKEN_ADJUST_PRIVILEGES
=
0x00000020;
internal
const
string
SE_SHUTDOWN_NAME
=
"SeShutdownPrivilege";
internal
const
int
EWX_LOGOFF
=
0x00000000;
internal
const
int
EWX_SHUTDOWN
=
0x00000001;
internal
const
int
EWX_REBOOT
=
0x00000002;
internal
const
int
EWX_FORCE
=
0x00000004;
internal
const
int
EWX_POWEROFF
=
0x00000008;
internal
const
int
EWX_FORCEIFHUNG
=
0x00000010;
//
通過調用WinAPI實現關機,主要代碼再最後一行ExitWindowsEx,這調用了同名的WinAPI,正好是關機用的。
private
static
void
DoExitWin(int
flg)
{
bool
ok;
TokPriv1Luid
tp;
IntPtr
hproc
=
GetCurrentProcess();
IntPtr
htok
=
IntPtr.Zero;
ok
=
OpenProcessToken(hproc,
TOKEN_ADJUST_PRIVILEGES
|
TOKEN_QUERY,
ref
htok);
tp.Count
=
1;
tp.Luid
=
0;
tp.Attr
=
SE_PRIVILEGE_ENABLED;
ok
=
LookupPrivilegeValue(null,
SE_SHUTDOWN_NAME,
ref
tp.Luid);
ok
=
AdjustTokenPrivileges(htok,
false,
ref
tp,
0,
IntPtr.Zero,
IntPtr.Zero);
ok
=
ExitWindowsEx(flg,
0);
}
private
void
button1_Click(object
sender,
EventArgs
e)
{
if
(radioButton1.Checked
==
true)
{
DoExitWin(EWX_SHUTDOWN);
}
else
{
Application.Exit();
}
//MessageBox.Show("2");
}
}
}