| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 992 人关注过本帖
标题:windows2000 xp 关机函数
只看楼主 加入收藏
guanqiang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-11-18
收藏
 问题点数:0 回复次数:9 
windows2000 xp 关机函数
Private Enum HowExitConst
EWX_LOGOFF = 0 ''注销
EWX_SHUTDOWN = 1 ''关机
EWX_REBOOT = 2 ''重新启动
EWX_FORCE = 4 '强制关机
End Enum
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Const ANYSIZE_ARRAY = 1
Private Type LUID
lowpart As Long
highpart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
Private Declare Function ExitWindowsEx Lib "User32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Dim method As HowExitConst
Dim Ydgqsql As String
Dim Ydgqdb As dao.Database
Dim Ydgqrs As dao.Recordset
Private Sub AdjustToken() '''获得系统授权函数,使程序有足够的优先权关机
Dim hdlProcessHandle As Long
Dim hdlTokenHandle As Long
Dim tmpLuid As LUID
Dim tkp As TOKEN_PRIVILEGES
Dim tkpNewButignored As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long
hdlProcessHandle = GetCurrentProcess()
OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkp.PrivilegeCount = 1
tkp.Privileges(0).pLuid = tmpLuid
tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
AdjustTokenPrivileges hdlTokenHandle, False, tkp, Len(tkpNewButignored), tkpNewButignored, lBufferNeeded
End Sub
Sub ExitWindowsGj() '''关机函数
method = EWX_SHUTDOWN
Call AdjustToken
Call ExitWindowsEx(method, 0)
End Sub



method = EWX_SHUTDOWN
DelAllSong.Enabled = True
ShellExecute 0, vbNullString, App.Path + "\end.bat", "", "", 0
Call AdjustToken '***关闭系统
Call ExitWindowsEx(method, 4)



method = EWX_REBOOT
DelAllSong.Enabled = True
ShellExecute 0, vbNullString, App.Path + "\end.bat", "", "", 0
Call AdjustToken '***重启系统
Call ExitWindowsEx(method, 2)
搜索更多相关主题的帖子: 函数 
2007-11-18 01:44
liwanxi
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-3-1
收藏
得分:0 
谢谢,收下了。

刚学C#,希望各位大侠指点,谢谢。
2007-11-18 07:07
qx988
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-11-18
收藏
得分:0 

呵呵,受教了

2007-11-18 07:15
reamercer
Rank: 1
等 级:新手上路
帖 子:20
专家分:3
注 册:2007-7-4
收藏
得分:0 
快速关机就是跳过一部分函数吧?







2007-11-19 08:06
lwwvb
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-11-8
收藏
得分:0 
呵呵,好.但在NET下,已经不用这么麻烦了.
2007-11-19 09:00
真的不该c
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-11-19
收藏
得分:0 
看不懂哦

当初真不该选择你,可是既然选择了前方就注定风雨兼程,行动是永远的金!我们一定行!!
2007-11-19 13:15
Borer
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-11-19
收藏
得分:0 
收下收下
2007-11-19 15:20
chenxue1949
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-9-21
收藏
得分:0 
头开始晕了!
2007-11-19 16:18
vivianson
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-11-5
收藏
得分:0 

不错不错!谢谢

2007-11-19 16:56
ads9527
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-11-18
收藏
得分:0 
这个是什么用途的,看不懂啊。
2007-11-20 14:41
快速回复:windows2000 xp 关机函数
数据加载中...
 
   



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

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