實戰基礎技能(12)--------C#程式登出、重啟、關機和鎖定電腦

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   使用   io   ar   2014   

一:

二:原始碼
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using System.Diagnostics;using System.Runtime.InteropServices;namespace 關機一鍵鎖定{    /// <summary>    /// MainWindow.xaml 的互動邏輯    /// </summary>    public partial class MainWindow : Window    {        public MainWindow()        {            InitializeComponent();        }        //關機        private void btnShutDown_Click(object sender, RoutedEventArgs e)        {            //Process p = new Process();//執行個體化一個獨立進程            //p.StartInfo.FileName = "shutdown";            //p.StartInfo.Arguments = "-s -t 0";            //p.Start();//啟動            //等價於上面四句            Process.Start("shutdown", "-s -t 0");                   }        private void btnReset_Click(object sender, RoutedEventArgs e)        {           //重啟            Process.Start("shutdown", "-r -t 0");        }        private void btnUnlogin_Click(object sender, RoutedEventArgs e)        {            //登出            Process.Start("shutdown", "-l ");//C#寫的關機、重啟、登出程式,代碼簡單主要是用Process類來操作        }        [DllImport("User32.DLL")]        public static extern void LockWorkStation();        //一鍵鎖定        private void btnClose_Click(object sender, RoutedEventArgs e)        {            LockWorkStation();        }        //開啟CMD視窗        private void btnCMD_Click(object sender, RoutedEventArgs e)        {            Process.Start("cmd");        }    }}

 

三:結語

當然我這樣做不是為了方便大家關機、重啟、登出和鎖定、開啟CMD視窗使用,微軟為大家提供很方便的快速鍵,如:win+r ,win+l等,不要再吐槽者方面了,僅供娛樂的代碼

實戰基礎技能(12)--------C#程式登出、重啟、關機和鎖定電腦

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.