| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2043 人关注过本帖
标题:关机程序与大家共享
取消只看楼主 加入收藏
wangfuli
Rank: 4
等 级:贵宾
威 望:12
帖 子:206
专家分:10
注 册:2005-11-11
收藏
 问题点数:0 回复次数:2 
关机程序与大家共享

8SWWQZMm.rar (41.76 KB) 关机程序与大家共享


[此贴子已经被作者于2006-5-6 20:40:51编辑过]



zwBoAjHO.rar (41.62 KB) 刚做的关机程序



Ey0PxxPL.rar (41.67 KB) 关机程序与大家共享

搜索更多相关主题的帖子: 共享 
2006-05-03 10:50
wangfuli
Rank: 4
等 级:贵宾
威 望:12
帖 子:206
专家分:10
注 册:2005-11-11
收藏
得分:0 

怎么也没人留个言,给个意见了?


2006-05-06 20:42
wangfuli
Rank: 4
等 级:贵宾
威 望:12
帖 子:206
专家分:10
注 册:2005-11-11
收藏
得分:0 
应大家的要求,下面的是关机程序的核心代码:
Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer
Public Enum RestartOptions
LogOff = 0
PowerOff = 8
Reboot = 2
ShutDown = 1
Suspend = -1
Hibernate = -2
End Enum
Protected Sub EnableToken(ByVal privilege As String)
If Not CheckEntryPoint("advapi32.dll", "AdjustTokenPrivileges") Then Return
Dim tokenHandle As IntPtr = IntPtr.Zero
Dim privilegeLUID = New LUID
Dim newPrivileges = New TOKEN_PRIVILEGES
Dim tokenPrivileges As TOKEN_PRIVILEGES
If (OpenProcessToken(Process.GetCurrentProcess().Handle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, tokenHandle)) = 0 Then Throw New PrivilegeException(FormatError(Marshal.GetLastWin32Error()))
If (LookupPrivilegeValue("", privilege, privilegeLUID)) = 0 Then Throw New PrivilegeException(FormatError(Marshal.GetLastWin32Error()))
tokenPrivileges.PrivilegeCount = 1
tokenPrivileges.Privileges.Attributes = SE_PRIVILEGE_ENABLED
tokenPrivileges.Privileges.pLuid = privilegeLUID
Dim Size As Integer = 4
If (AdjustTokenPrivileges(tokenHandle, 0, tokenPrivileges, 4 + (12 * tokenPrivileges.PrivilegeCount), newPrivileges, Size)) = 0 Then Throw New PrivilegeException(FormatError(Marshal.GetLastWin32Error()))
End Sub
Private Sub logoff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
If MessageBox.Show("你确定要注销吗?", "关闭计算机", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
Dim shutdown As New WindowsController
shutdown.ExitWindows(shutdown.RestartOptions.LogOff, 0)
Application.Exit()
End If
End Sub
Private Sub shutdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If MessageBox.Show("你确定要关机吗?", "关闭计算机", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
shutdown.ExitWindows(shutdown.RestartOptions.PowerOff, True)
Application.Exit()
End If
只有定时只要设置一个timer就可以了
End Sub

2006-06-09 20:49
快速回复:关机程序与大家共享
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026821 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved