我想弄个重新启动计算机的代码在一个按钮上,请看。
Option Explicit
Private Const ewx_reboot As Long = 2
Private Const ewx_force As Long = 4
Private Const ewx_poweroff As Long = 8
Private Declare Function exitwindowsex Lib "user32" (ByVal dwoptions As Long, ByVal dwreserved As Long) As Long
Private Declare Function getlasterror Lib "kernel32" () As Long
Private Type luid
usedpart As Long
ignoredfornowhigh32bitpart As Long
End Type
Private Type luid_and_attributes
theluid As luid
attributes As Long
End Type
Private Type token_privileges
privilegecount As Long
theluid As luid
attributes As Long
End Type
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 Declare Sub setlasterror Lib "kernel32" (ByVal dwerrcode As Long)
Private Const mlngwindow95 = 0
Private Const mlngwindowsnt = 1
Public glngwhichwindows32 As Long
Private Declare Function getversion Lib "kernel32" () 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
setlasterror 0
hdlprocesshandle = getcurrentprocess()
openprocesstoken hdlprocesshandle, (token_adjust_privileges Or token_Query), hdltokenhandle
lookupprivilegevalue "", "seshutdownprivilege", tmpluid
tkp.privilegecount = 1
tkp.theluid = tmpluid
tkp.attributes = se_privilege_enabled
adjusttokenprivileges hdltokenhandle, flase, tkp, Len(tkpnewbutignored), tkpnewbutignored, lbufferneeded
End Sub
Private Sub Command1_Click()
If glngwhichwindows32 = mlngwindowsnt Then
adjusttoken
End If
End Sub
Private Sub Form_Load()
Dim lngversion As Long
lngversion = getversion()
glngwhichwindows32 = mlngwindowsnt
End Sub
到了运行的时候,它老是说“找不到DLL入口点 getversion in kernel32”,我计算机的系统是Windows XP的,会不会有些问题。
请您尽快给我回复,帮帮忙,我这个作业可以要交的,摆脱了,谢谢! |