图
以上界面工作基本完成现在需要输入代码了
双击窗体进入常规 声明Public Class Form 事件中
CODE
Imports System Runtime InteropServicesImports Microsoft VisualBasicPublic Class Form_ 调用系统参数Friend Shared Function GetCurrentProcess() As IntPtrEnd Function
_Friend Shared Function OpenProcessToken(ByVal h As IntPtr
ByVal acc As Integer ByRef phtok As IntPtr) As BooleanEnd Function
_Friend Shared Function LookupPrivilegeValue(ByVal host As String
ByVal name As String ByRef pluid As Long) As BooleanEnd Function
_Friend Shared Function AdjustTokenPrivileges(ByVal htok As IntPtr
ByVal disall As Boolean ByRef newst As TokPriv Luid
ByVal len As Integer ByVal prev As IntPtr
ByVal relen As IntPtr) As BooleanEnd Function
_Friend Shared Function ExitWindowsEx(ByVal flg As Integer
ByVal rea As Integer) As BooleanEnd Function
Friend Const SE_PRIVILEGE_ENABLED As Integer = H Friend Const TOKEN_QUERY As Integer = H Friend Const TOKEN_ADJUST_PRIVILEGES As Integer = H Friend Const SE_SHUTDOWN_NAME As String = SeShutdownPrivilege Friend Const EWX_LOGOFF As Integer = H 注销计算机Friend Const EWX_SHUTDOWN As Integer = H 关闭计算机Friend Const EWX_REBOOT As Integer = H 重新启动计算机Friend Const EWX_FORCE As Integer = H 关闭所有进程 注销计算机Friend Const EWX_POWEROFF As Integer = H Friend Const EWX_FORCEIFHUNG As Integer = H
_引用参数 Friend Structure TokPriv Luid Public Count As Integer Public Luid As Long Public Attr As IntegerEnd Structure
Private Shared Sub DoExitWin(ByVal flg As Integer) Dim xc As Boolean 判断语句 Dim tp As TokPriv Luid Dim hproc As IntPtr = GetCurrentProcess()调用进程值 Dim htok As IntPtr = IntPtr Zero xc = OpenProcessToken(hproc TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY htok) tp Count =tp Luid =tp Attr = SE_PRIVILEGE_ENABLED xc = LookupPrivilegeValue(Nothing SE_SHUTDOWN_NAME tp Luid) xc = AdjustTokenPrivileges(htok False tp IntPtr Zero IntPtr Zero) xc = ExitWindowsEx(flg )End Sub
Public Shared Sub Reboot() DoExitWin((EWX_FORCE Or EWX_REBOOT)) 重新启动计算机End Sub
Public Shared Sub PowerOff() DoExitWin((EWX_FORCE Or EWX_POWEROFF)) 关闭计算机End Sub
Public Shared Sub LogoOff() DoExitWin((EWX_FORCE Or EWX_LOGOFF)) 注销计算机End Sub
Dim entTime As Object 保存输入时间Dim xianzaiTime As Object 保存实时时间Dim startTime As Object 保存开始定时时间
注销button 按钮输入code
Private Sub Button _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Button ClickLogoOff() 注销计算机End Sub
双击重新启动按钮button 输入code
Private Sub Button _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Button Click
Reboot()
End Sub
双击关闭计算机按钮button 输入code
Private Sub Button _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Button Click startTime = TimeOfDay If Not IsDate(TextBox Text) Then 用IsData函数判断输入的时间格式MsgBox( 你所输入的不是时间格式 ! 错误 ) ElseentTime = TimeValue(TextBox Text) End If Timer Enabled = True启动定时器 Me WindowState = System Windows Forms FormWindowState Minimized最小化窗体
End Sub
如图
图
双击timer 控件如图
图
输入代码
Private Sub Timer _Tick(ByVal sender As System Object
ByVal e As System EventArgs) Handles Timer Tick xianzaiTime = TimeOfDay If RadioButton Checked Then
If DateDiff(Microsoft VisualBasic DateInterval Second
xianzaiTime entTime)Then 用DateDiff函数判断是否到时间了
End IfEnd If
PowerOff() 关闭计算机End Sub
好了 基本上一个定时关机程序就完成了 接下来加一个超级链接吧!当然对于高手来说可能是废话 但是对于新手来说这也是必备的 这个超级链接当然是我们最喜欢的天极网开发频道了
推荐阅读
- 实训一linux基本命令,实训2 linux基本命令
- 电脑音量不能保存怎么办,电脑上面的音量不能调节是因为什么
- 写毕业设计用啥软件好,写毕业设计用啥软件好呢
- 阿里云轻量应用服务器,阿里云轻量应用服务器是什么
- go语言需要多久入门 go语言自学
- 相册可以放微信吗视频号,相册里的视频可以发朋友圈吗
- redis使用的业务场景,redis实际应用场景
- linux命令行并行 linuxshell并行执行
- 如何查看mysqlroot密码是多少的简单介绍