標籤: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#程式登出、重啟、關機和鎖定電腦