hedit

时间:2024-08-28 10:30:22编辑:莆田seo君

VB自动关机程序

完整代码
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
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
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
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Const HELP_CONTENTS = &H3&
Const EWX_LOGOFF = 0 '注销
Const EWX_SHUTDOWN = 1 '待机
Const EWX_REBOOT = 2 '重新启动
Const EWX_WAIT = 16
Const EWX_FORCE = 4 '终止没有响应的进程
Const EWX_POWEROFF = 8 '关闭电源
Private Sub Form_Load()
Dim hProcessHandle As Long
Dim hTokenHandle As Long
Dim tmpLuid As LUID
Dim tkpNew As TOKEN_PRIVILEGES
Dim tkpPrevious As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long
'获取当前进程的一个伪句柄
hProcessHandle = GetCurrentProcess()
OpenProcessToken hProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hTokenHandle
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkpNew.PrivilegeCount = 1
tkpNew.TheLuid = tmpLuid
tkpNew.Attributes = SE_PRIVILEGE_ENABLED
lBufferNeeded = 0
'允许当前应用程序有关闭操作系统的权限
AdjustTokenPrivileges hTokenHandle, False, tkpNew, Len(tkpPrevious), tkpPrevious, lBufferNeeded
end sub
Private Sub Command1_Click()
ExitWindowsEx EWX_FORCE Or EWX_POWEROFF, 0
End Sub


VB做一个自动关机

用vb的SHELL()函数可以执行外部命令.
自动关机 的命令绍介如下:
自动关机是计算机的一个命令。常见的有windows的自动关机,还有嵌入式系统手机系统的自动关机。 使用“shutdown”可以让电脑自动关机,不过如果打开很多文档就会提示你保存文件不,你不去手动确定,shutdown这个命令是没用的。比如你的电脑要在22:00关机,可以选择“开始→运行”,输入“at 22:00 Shutdown -s”, 这样,到了22点电脑就会出现“系统关机”对话框,默认有30秒钟的倒计时并提示你保存工 作。如果你想以倒计时的方式关机,可以输入“Shutdown.exe -s -t 3600”,这里表示60 分钟后自动关机,“3600”代表60分钟。 设置好自动关机后,如果想取消的话,可以在运行中输入“shutdown -a”。另外输入 “shutdown -i”,则可以打开设置自动关机对话框,对自动关机进行设置。 Shutdown.exe的参数,每个都具有特定的用途,执行每一个都会产生不同的效果,比如 “-s”就表示关闭本地计算机,“-a”表示取消关机操作,下面列出了更多参数,大家 可以在Shutdown.exe中按需使用。 -f:强行关闭应用程序 -m \\计算机名:控制远程计算机 -i:显示图形用户界面,但必须是Shutdown的第一个选项 -l:注销当前用户 -r:关机并重启 -t 时间:设置关机倒计时 -c "消息内容":输入关机对话框中的消息内容(不能超127个字符)


上一篇:学习软件

下一篇:我是大侦探下载