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#實(shí)現(xiàn)在匿名方法中捕獲外部變量的方法
這篇文章主要介紹了C#實(shí)現(xiàn)在匿名方法中捕獲外部變量的方法,本文直接給出代碼實(shí)例,然后分析了代碼中的一些知識點(diǎn),需要的朋友可以參考下2015-03-03
c#遠(yuǎn)程html數(shù)據(jù)抓取實(shí)例分享
這篇文章主要介紹了c#遠(yuǎn)程html數(shù)據(jù)抓取的方法,大家參考使用吧2013-12-12
Unity Shader實(shí)現(xiàn)水波紋效果
這篇文章主要為大家詳細(xì)介紹了Unity Shader實(shí)現(xiàn)水波紋效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-05-05

