| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 819 人关注过本帖
标题:使用函数关机时发生错误
只看楼主 加入收藏
炫色流年
Rank: 2
等 级:论坛游民
帖 子:61
专家分:18
注 册:2011-8-8
结帖率:38.46%
收藏
 问题点数:0 回复次数:9 
使用函数关机时发生错误
代码如下:
Private Declare Function exitwindowsex Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
-----------
Private Sub Form_Load()
Dim X As Long

Const EWX_SHUTDOWN = 1
Const ewx_logoff = 0
Const ewx_reboot = 2
Const ewx_force = 4
Const ewx_poweroff = 8

X = exitwindowsex(EWX_SHUTDOWN, dwReserved)

End Sub
--------------------------------------
为什么我运行时提示:实时错误‘453’:
找不到DLL入口点exitwindowsex in user32

这句话X = exitwindowsex(EWX_SHUTDOWN, dwReserved)报错
---------------------------------
请各位高手指点迷津!
2011-09-30 17:56
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:0 
注意大小写。
2011-09-30 18:59
炫色流年
Rank: 2
等 级:论坛游民
帖 子:61
专家分:18
注 册:2011-8-8
收藏
得分:0 
程序代码:
Private Declare Function exitwindowsex Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Sub Form_Load()
Dim X As Long

Const EWX_SHUTDOWN = 1
Const EWX_LOGOFF = 0
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const EWX_POWEROFF = 8
Const EWX_RESET = EWX_LOGOFF + EWX_FORCE + EWX_REBOOT
X = exitwindowsex(EWX_REXET, dwReserved)

End Sub
没有用啊,依然是那个错误
2011-10-04 22:11
a414715440
Rank: 2
等 级:论坛游民
帖 子:37
专家分:26
注 册:2011-8-28
收藏
得分:0 
很明显,你的是有错的,这个程序是不需要返回值的吧,你直接exitwindowsex EWX_SHUTDOWN, 1 试试,

[ 本帖最后由 a414715440 于 2011-10-4 22:18 编辑 ]
2011-10-04 22:17
炫色流年
Rank: 2
等 级:论坛游民
帖 子:61
专家分:18
注 册:2011-8-8
收藏
得分:0 
噢,犯了个低级错误。。。
exitwindowsex应该为ExitWindowsEx

但为什么只能注销,而不是重启???
2011-10-04 22:17
a414715440
Rank: 2
等 级:论坛游民
帖 子:37
专家分:26
注 册:2011-8-28
收藏
得分:0 
回复 5楼 炫色流年
这个问题我也试过无数次,只能注销,最好你直接调用系统的,关机程序,
2011-10-04 22:19
炫色流年
Rank: 2
等 级:论坛游民
帖 子:61
专家分:18
注 册:2011-8-8
收藏
得分:0 
什么叫“直接调用系统的,关机程序”?????
2011-10-04 22:37
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:0 
程序代码:
Option Explicit

Private Type LUID
UsedPart As Long
IgnoredForNowHigh32BitPart As Long
End Type

Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type

' Beginning of Code
Private Const EWX_SHUTDOWN As Long = 1
Private Const EWX_FORCE As Long = 4
Private Const EWX_REBOOT = 2

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 TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Sub AdjustToken()

Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
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

' Get the LUID for shutdown privilege.
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid

tkp.PrivilegeCount = 1 ' One privilege to set
tkp.TheLuid = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED

' Enable the shutdown privilege in the access token of this
' process.
AdjustTokenPrivileges hdlTokenHandle, False, tkp, _
Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded

End Sub

Private Sub cmdForceShutdown_Click()
AdjustToken
ExitWindowsEx (EWX_SHUTDOWN Or EWX_FORCE Or EWX_REBOOT), &HFFFF
End Sub
有些需要提权。
2011-10-04 22:41
a414715440
Rank: 2
等 级:论坛游民
帖 子:37
专家分:26
注 册:2011-8-28
收藏
得分:0 
回复 8楼 bczgvip
版主,帮我的那个贴子看看吧,就在他的这个贴子下面,
2011-10-04 22:52
炫色流年
Rank: 2
等 级:论坛游民
帖 子:61
专家分:18
注 册:2011-8-8
收藏
得分:0 
作为菜鸟的我彻底晕了,版主就是
2011-10-04 23:00
快速回复:使用函数关机时发生错误
数据加载中...
 
   



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

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