国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

使用C#實現(xiàn)關(guān)機、鎖定電腦和注銷功能的源代碼

2023-05-17 11:41:58
字體:
供稿:網(wǎng)友

下面是在C#中實現(xiàn)關(guān)機、注銷和鎖定電腦的源代碼。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;
using System.Diagnostics;
//using System.Configuration;
//using System.Xml ;

——————————————————————————————————————

// 鎖定計算機.
[DllImport("user32.dll")]
private static extern void LockWorkStation();//須寫extern
private void button1_Click(object sender, EventArgs e)
{
LockWorkStation();
}
//注銷計算機
[DllImport("user32.dll", EntryPoint = "ExitWindowsEx", CharSet = CharSet.Ansi)]
private static extern int ExitWindowsEx(int a,int b);
private void button1_Click(object sender, EventArgs e)
{
ExitWindowsEx(0, 0);
}
//關(guān)閉計算機.
private void button3_Click(object sender, EventArgs e)
{
System.Diagnostics.Process mp = new System.Diagnostics.Process();
mp.StartInfo.FileName = "cmd.exe";
mp.StartInfo.RedirectStandardInput = true;
mp.StartInfo.RedirectStandardOutput = true;
mp.StartInfo.RedirectStandardError = true;
mp.StartInfo.UseShellExecute = false;
mp.StartInfo.CreateNoWindow = true;
mp.Start();//啟動進程
mp.StandardInput.WriteLine("shutdown -s -t 0");//關(guān)機
}
//重啟計算機
private void button3_Click(object sender, EventArgs e)
{
System.Diagnostics.Process mp = new System.Diagnostics.Process();
mp.StartInfo.FileName = "cmd.exe";
mp.StartInfo.RedirectStandardInput = true;
mp.StartInfo.RedirectStandardOutput = true;
mp.StartInfo.RedirectStandardError = true;
mp.StartInfo.UseShellExecute = false;
mp.StartInfo.CreateNoWindow = true;
mp.Start();//啟動進程
mp.StandardInput.WriteLine("shutdown -r -t 0");//重啟
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 嘉禾县| 商水县| 永嘉县| 兴山县| 无锡市| 灵台县| 满城县| 方山县| 上饶县| 寿宁县| 勐海县| 南通市| 延安市| 璧山县| 航空| 盘锦市| 新野县| 日喀则市| 牡丹江市| 云阳县| 德兴市| 江山市| 且末县| 文昌市| 峨边| 吉林市| 汉寿县| 苏州市| 永德县| 胶州市| 佛坪县| 寿宁县| 钟山县| 若羌县| 黔西县| 合作市| 惠来县| 嘉定区| 德令哈市| 略阳县| 吉木萨尔县|