社区
C#
帖子详情
求windows关机代码(C#)
werwsxwdfwdc
2004-12-28 07:43:50
求windows关机代码(C#)
...全文
231
6
打赏
收藏
求windows关机代码(C#)
求windows关机代码(C#)
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
代码蜗牛sky
2004-12-28
打赏
举报
回复
namespace ShutDownTest {
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Security.Principal;
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct LUID
{
public uint LowPart;
public uint HighPart;
};
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct TOKEN_PRIVILEGES
{
public uint PrivilegeCount;
public LUID Luid;
public uint Attributes;
};
public class PlatformImport
{
[DllImport("advapi32", CharSet=CharSet.Auto)]
public static extern bool LookupPrivilegevalue (string sysname,string privname,ref LUID luid);
[DllImport("advapi32", CharSet=CharSet.Auto)]
public static extern bool AdjustTokenPrivileges(IntPtr handle, bool dsall,ref TOKEN_PRIVILEGES newstate,int len, IntPtr oldstate,IntPtr retlen);
[DllImport("kernel32.dll")]
public static extern int GetLastError();
[DllImport("user32.dll")]
public static extern bool ExitWindowsEx(int uFlags, int dwReason);
}
public class Form1 : Form
{
private Button button1;
public Form1()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new Point(136, 112);
this.button1.Name = "button1";
this.button1.Size = new Size(80, 24);
this.button1.TabIndex = 0;
this.button1.Text = "Shut Down";
this.button1.Click += new EventHandler(this.button1_Click);
this.AutoScaleBaseSize = new Size(6, 14);
this.ClientSize = new Size(292, 273);
this.Controls.Add(button1);
this.Name = "Form1";
this.Text = "shutdown test";
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
IntPtr token = identity.Token;
IntPtr luid = (IntPtr)0;
IntPtr previousState = (IntPtr)0;
IntPtr previousStateLength = (IntPtr)0;
LUID privilegeId = new LUID ();
PlatformImport.LookupPrivilegevalue ("", "SeShutdownPrivilege", ref privilegeId);
TOKEN_PRIVILEGES privileges = new TOKEN_PRIVILEGES();
privileges.PrivilegeCount = 1;
privileges.Luid = privilegeId;
privileges.Attributes = 2;
PlatformImport.AdjustTokenPrivileges (token, false, ref privileges, Marshal.SizeOf(privileges), previousState, previousStateLength);
if (PlatformImport.GetLastError() != 0) return;
if(!(PlatformImport.ExitWindowsEx(0x01 | 0x04, 0))) return;
}
}
}
lucbesson
2004-12-28
打赏
举报
回复
http://search.csdn.net/Expert/topic/2542/2542604.xml?temp=.6864282
antoniusguo
2004-12-28
打赏
举报
回复
这是什么?
document.write("\n"); document.write("\n"); document.write(""); ???
我也很想知道
nga96
2004-12-28
打赏
举报
回复
兄弟我收藏过,可惜一下找不到,晕死
兔子-顾问
2004-12-28
打赏
举报
回复
document.write("\n"); document.write("\n"); document.write(""); ???
楼上的哥们。给的是啥?
kqh0319
2004-12-28
打赏
举报
回复
http://universalmccannafa.allyes.com/main/adfshow?user=universalmccann|csdn|Homepage_Fullcolum_770_90&db=universalmccannafa&border=0&local=yes&js=ie
C#
捕获
windows
关机
事件,在系统
关机
前做一些自己想做的事
本文介绍如何在
C#
中捕获
Windows
关机
事件,以便在系统
关机
前执行特定操作,如日志记录或数据保存。
关于利用
C#
实现
windows
的自动
关机
本文介绍两种使用
C#
语言实现
Windows
系统自动
关机
的方法。第一种方法通过创建窗口程序并利用DispatcherTimer定时调用shutdown.exe命令实现
关机
;第二种方法同样创建窗口程序,但通过Process.Start()启动cmd.exe执行
关机
命令。两种方法均需处理异常并确保程序稳定运行。
C#
实现
windows
系统重启、
关机
本文详细介绍了如何使用
C#
语言通过System.Diagnostics.Process和APIHelper类实现
Windows
系统的
关机
、重启和注销操作,包括shutdown命令参数解析以及
C#
代码
示例。
C#
定时
关机
小程序
本文介绍了如何使用
C#
开发一个简单的定时
关机
程序。作者选择
C#
是因为其适合
Windows
系统,借助Visual Studio 2017和IntelliCode插件进行开发。程序通过调用shutdown.exe命令实现
关机
功能,对于不支持计时的注销和休眠操作,利用
C#
计时器控件完成。在执行命令前需确保中止计时器线程,防止意外的循环
关机
问题。
windows
关机
代码
本文介绍了两种
Windows
系统下实现
关机
功能的方法:一是通过调用shutdown命令;二是利用
C#
调用
Windows
底层函数Exit
Windows
Ex。第一种方法简单易行但会弹出对话框。第二种方法更为灵活,可通过设置权限来实现不同类型的
关机
操作。
C#
111,128
社区成员
642,534
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章