C#實(shí)現(xiàn)控制Windows系統(tǒng)關(guān)機(jī)、重啟和注銷的方法
本文實(shí)例講述了C#實(shí)現(xiàn)控制Windows系統(tǒng)關(guān)機(jī)、重啟和注銷的方法。分享給大家供大家參考。具體分析如下:
使用.NET和C#.NET,我們可以對當(dāng)前PC執(zhí)行關(guān)機(jī),重啟,注銷操作。
NET Framework中,有一個(gè)命名空間System.Diagnostics具有所需的類和方法,從當(dāng)前PC上運(yùn)行.NET應(yīng)用程序來執(zhí)行這些操作。
請使用下面的按鈕來執(zhí)行關(guān)機(jī),重啟和注銷。
下面是一個(gè)winform程序
//SHUT DOWN
protected void btnShutDown_Click(object sender, EventArgs e)
{
Process.Start("shutdown.exe", "-s");
// By Default the Shutdown will take place after 30 Seconds
//if you want to change the Delay try this one
Process.Start("shutdown.exe","-s -t xx");
//Replace xx with Seconds example 10,20 etc
}
//RESTART
protected void btnRestart_Click(object sender, EventArgs e)
{
Process.Start("shutdown.exe", "-r");
// By Default the Restart will take place after 30 Seconds
//if you want to change the Delay try this one
Process.Start("shutdown.exe","-r -t 10");
//Replace xx with Seconds example 10,20 etc
}
// LOG OFF
protected void btnLogOff_Click(object sender, EventArgs e)
{
Process.Start("shutdown.exe", "-l");
//This Code Will Directly Log Off the System Without warnings
}
希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#中DateTime.Compare()比較時(shí)間大小
本文主要介紹了C#中DateTime.Compare()比較時(shí)間大小,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04
C# VB 實(shí)現(xiàn)10進(jìn)制 16進(jìn)制之間互相轉(zhuǎn)換
如何將10進(jìn)制轉(zhuǎn)成16進(jìn)制,又如何將16進(jìn)制數(shù)轉(zhuǎn)成10進(jìn)制,本文將介紹C#和VB實(shí)現(xiàn)代碼,需要了解的朋友可以參考下2012-11-11
c#實(shí)現(xiàn)簡單控制臺udp異步通信程序示例
這篇文章主要介紹了c#實(shí)現(xiàn)簡單控制臺udp異步通信程序示例,需要的朋友可以參考下2014-04-04

