社区
C#
帖子详情
求windows关机代码(C#)
werwsxwdfwdc
2004-12-28 07:43:50
求windows关机代码(C#)
...全文
202
6
打赏
收藏
求windows关机代码(C#)
求windows关机代码(C#)
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用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#
关机
源
代码
C#
关机
源
代码
Shutdown
首先,
C#
本身并不直接提供
关机
系统的功能,但可以通过调用
Windows
API来实现。
Windows
API是一组函数,允许程序员访问操作系统的核心服务。在
C#
中,我们可以使用`DllImport`特性来导入这些函数。 关键API函数是`...
C# 自动
关机
源
代码
这个自动
关机
代码
提供了便利,可以在预设的时间或者满足特定条件时自动执行
关机
操作,无需人工干预。“简单易懂,可在后台运行”意味着该
代码
设计得易于理解和修改,同时也能够在用户进行其他操作时默默地在后台执行...
C#
语言编程 计算机
关机
代码
(
C#
编程)
总结来说,
C#
编程中实现计算机
关机
、重启和注销涉及到对操作系统底层功能的调用,可以使用
Windows
API函数或.NET Framework的类。在实际应用中,确保有足够的权限并妥善处理异常情况是至关重要的。此外,开发这类...
c#
写的一个远程
关机
1. **
C#
与系统API交互**:
C#
本身并不直接支持远程
关机
这样的功能,但是可以通过P/Invoke(Platform Invoke)技术调用
Windows
API来实现。P/Invoke允许.NET Framework应用程序调用非托管
代码
,即操作系统内核提供的...
C#
远程
关机
源
代码
本项目名为"
C#
远程
关机
源
代码
",它利用了
C#
的
Windows
Management Instrumentation(WMI)技术来实现远程计算机的
关机
功能。WMI是微软提供的一个系统管理接口,它允许开发者通过脚本或编程方式来访问和控制
Windows
...
C#
111,097
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章