VB中命令控件单击触发后怎么让它的效果是在一定的时间内关机
发布网友
发布时间:2022-05-11 01:38
我来回答
共2个回答
热心网友
时间:2023-11-24 09:13
Private Sub Command1_Click()'定时关机
Shell "shutdown -s -t 30"
End Sub
Private Sub Form_Unload(Cancel As Integer) '关闭按钮,我假设你要弹出的窗口是FORM2
form2.Show
End Sub
热心网友
时间:2023-11-24 09:13
Attribute VB_Name = "WinClosemode"
Option Explicit
Private Const EWX_LogOff As Long = 0
Private Const EWX_SHUTDOWN As Long = 1
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
Public Const mlngWindows95 = 0
Public Const mlngWindowsNT = 1
Public glngWhichWindows32 As Long
Private Declare Function GetVersion 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 TypePrivate 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 Declare Sub SetLastError Lib "kernel32" (ByVal dwErrCode As Long)
Public Sys_NowTime As Date
Public Sys_StartTime As Date
Public Sys_CloseTime As Date
Public Sys_Tmptime As Date
Public Sys_Ding As Boolean'关机过程SUB
Function GetMytitle(index As Boolean) As String
GetMytitle = "定时关机" + CStr(App.Major) + "." + CStr(App.Minor) + IIf(index, IIf(Sys_Ding, "-定时中", ""), "")
End Function
Public Sub ShutDownWindowsNT()
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, False, tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded
End Sub
Public Sub ShutDownWindows9X()
ExitWindowsEx (EWX_SHUTDOWN), &HFFFF
End SubPublic Sub CloseWindowsNow()
If glngWhichWindows32 = mlngWindowsNT Then
ShutDownWindowsNT
End If
ShutDownWindows9X
End
End SubFunction SetWindowsVer() As Boolean
Dim lngVersion As Long
lngVersion = GetVersion()
If ((lngVersion And &H80000000) = 0) Then
glngWhichWindows32 = mlngWindowsNT
Else
glngWhichWindows32 = mlngWindows95
End If
End Function按钮调用:CloseWindowsNow()