| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1019 人关注过本帖
标题:请问关机的代码是什么?
只看楼主 加入收藏
新手变高手
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2006-3-10
收藏
 问题点数:0 回复次数:4 
请问关机的代码是什么?
请问关机的代码是什么?急需,谢谢!
搜索更多相关主题的帖子: 代码 
2006-04-08 11:46
leon2
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:731
专家分:0
注 册:2005-3-18
收藏
得分:0 
这个论坛以前有过解决这个问题的帖子,搜索以下
2006-04-08 12:32
新手变高手
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2006-3-10
收藏
得分:0 
不会告诉我又是用exitwindowex这个函数吧,我用过了,只会注销而已,根本就不会重启或关机,我想对Win98才会有效,请版主快来解决我刚才的问题啊!!!!
2006-04-08 14:26
leon2
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:731
专家分:0
注 册:2005-3-18
收藏
得分:0 
看这个百度知道的答案吧,有够你看了!!!超长!!

http://zhidao.baidu.com/question/2336519.html

[此贴子已经被作者于2006-4-8 17:28:36编辑过]

2006-04-08 17:28
lnhsgj
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2006-4-8
收藏
得分:0 

Option Explicit
Private Const TOKEN_ADJUST_PRIVILEGES As Long = &H20
Private Const TOKEN_QUERY As Long = &H8
Private Const SE_PRIVILEGE_ENABLED As Long = &H2

Private Const EWX_LOGOFF As Long = &H0
Private Const EWX_SHUTDOWN As Long = &H1
Private Const EWX_REBOOT As Long = &H2
Private Const EWX_FORCE As Long = &H4
Private Const EWX_POWEROFF As Long = &H8
Private Const EWX_FORCEIFHUNG As Long = &H10 '2000/XP only

Private Const VER_PLATFORM_WIN32_NT As Long = 2

Private Type OSVERSIONINFO
OSVSize As Long
dwVerMajor As Long
dwVerMinor As Long
dwBuildNumber As Long
PlatformID As Long
szCSDVersion As String * 128
End Type

Private Type LUID
dwLowPart As Long
dwHighPart As Long
End Type

Private Type LUID_AND_ATTRIBUTES
udtLUID As LUID
dwAttributes As Long
End Type

Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
laa As LUID_AND_ATTRIBUTES
End Type

Private Declare Function ExitWindowsEx Lib "user32" _
(ByVal dwOptions As Long, _
ByVal dwReserved As Long) As Long

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

Private Declare Function OpenProcessToken Lib "advapi32" _
(ByVal ProcessHandle As Long, _
ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long

Private Declare Function LookupPrivilegeValue Lib "advapi32" _
Alias "LookupPrivilegeValueA" _
(ByVal lpSystemName As String, _
ByVal lpName As String, _
lpLuid As LUID) As Long

Private Declare Function AdjustTokenPrivileges Lib "advapi32" _
(ByVal TokenHandle As Long, _
ByVal DisableAllPrivileges As Long, _
NewState As TOKEN_PRIVILEGES, _
ByVal BufferLength As Long, _
PreviousState As Any, _
ReturnLength As Long) As Long

Private Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long



Private Sub Command1_Click()

Dim uflags As Long
Dim success As Long

If Option1.Value = True Then uflags = EWX_LOGOFF
If Option2.Value = True Then uflags = EWX_SHUTDOWN
If Option3.Value = True Then uflags = EWX_REBOOT
If Option4.Value = True Then uflags = EWX_POWEROFF

If Check1.Value = vbChecked Then uflags = uflags Or EWX_FORCE
If Check2.Value = vbChecked Then uflags = uflags Or EWX_FORCEIFHUNG

success = True

If IsWinNTPlus Then
success = EnableShutdownPrivledges()
End If

If success Then Call ExitWindowsEx(uflags, 0&)

End Sub


Private Function IsWinNTPlus() As Boolean

#If Win32 Then

Dim OSV As OSVERSIONINFO

OSV.OSVSize = Len(OSV)

If GetVersionEx(OSV) = 1 Then

IsWinNTPlus = (OSV.PlatformID = VER_PLATFORM_WIN32_NT) And _
(OSV.dwVerMajor >= 4)
End If

#End If

End Function


Private Function EnableShutdownPrivledges() As Boolean

Dim hProcessHandle As Long
Dim hTokenHandle As Long
Dim lpv_la As LUID
Dim token As TOKEN_PRIVILEGES

hProcessHandle = GetCurrentProcess()

If hProcessHandle <> 0 Then

If OpenProcessToken(hProcessHandle, _
(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), _
hTokenHandle) <> 0 Then

If LookupPrivilegeValue(vbNullString, _
"SeShutdownPrivilege", _
lpv_la) <> 0 Then

With token
End With

If AdjustTokenPrivileges(hTokenHandle, _
False, _
token, _
ByVal 0&, _
ByVal 0&, _
ByVal 0&) <> 0 Then

EnableShutdownPrivledges = True

End If 'AdjustTokenPrivileges
End If 'LookupPrivilegeValue
End If 'OpenProcessToken
End If 'hProcessHandle

End Function


2006-04-08 18:08
快速回复:请问关机的代码是什么?
数据加载中...
 
   



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

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