【VB开源代码栏目提醒】:网学会员鉴于大家对VB开源代码十分关注,论文会员在此为大家搜集整理了“【精品】自动关机—vb程序代码 - 其它资料”一文,供大家参考学习
Form1(主界面)Private Declare Function GetCurrentProcess Lib kernel32 As LongPrivate Declare Function OpenProcessToken Lib advapi32 ByVal ProcessHandle As LongByVal DesiredAccess As Long TokenHandle As Long As LongPrivate Declare Function LookupPrivilegeValue Lib advapi32 Alias LookupPrivilegeValueAByVal lpSystemName As String ByVal lpName As String lpLuid As LUID As LongPrivate Declare Function AdjustTokenPrivileges Lib advapi32 ByVal TokenHandle As LongByVal DisableAllPrivileges As Long NewState As TOKEN_PRIVILEGES ByVal BufferLengthAs Long PreviousState As TOKEN_PRIVILEGES ReturnLength As Long As LongConst TOKEN_ADJUST_PRIVILEGES H20Const TOKEN_QUERY H8Const SE_PRIVILEGE_ENABLED H2Private Type LUID UsedPart As Long IgnoredForNowHigh32BitPart As LongEnd TypePrivate Type TOKEN_PRIVILEGES PrivilegeCount As Long TheLuid As LUID Attributes As LongEnd TypePrivate Declare Function ExitWindowsEx Lib user32 ByVal uFlags As Long ByValdwReserved 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 关闭电源Const xStr As String 0123456789窗口在前Private Declare Function SetWindowPos Lib user32 ByVal hWnd As Long ByValhWndInsertAfter As Long ByVal X As Long ByVal Y As Long ByVal cx As Long ByVal cy AsLong ByVal wFlags As Long As LongPrivate Const HWND_TOPMOST -1Private Const SWP_NOSIZE H1Private Const SWP_NOMOVE H2Dim WindowTop WindowLeftPublic txt As LongPrivate Sub Command1_Click 确定 If Command1.Caption 设定 Then Text1.Enabled True Text1.SetFocus Command1.Caption 确定 Label1.Caption 请输入关机时间: Label2.Caption 如 22 时 55 分 30 秒关机则输入 225530 Exit Sub ElseIf Command1.Caption 确定 Then If LenText1 6 Then Call sjcw Text1 Text1.SetFocus Else b1 FormatMidText1 1 2 00 b2 FormatMidText1 3 2 00 b3 FormatMidText1 5 2 00 If b1 23 Or b2 59 Or b3 59 Then Call sjcw Else pdt Text1 关机时间 Text1.Enabled False Command1.Caption 修改 Label1.Caption 关机时间为: b1 : b2 : b3 Label2.Caption 点击“启动”开启自动关机功能 Command2.Enabled True Exit Sub End If End If Else Text1.Enabled True Text1.SetFocus Command1.Caption 确定 Label1.Caption 请输入关机时间: Label2.Caption 如 22 时 55 分 30 秒关机则输入 225530 Exit Sub End IfEnd SubPrivate Sub Command2_Click 启动 If Command2.Caption 启动 Then b1 FormatMidText1 1 2 00 b2 FormatMidText1 3 2 00 b3 FormatMidText1 5 2 00 If b1 23 Or b2 59 Or b3 59 Then Call sjcw Else Open App.Path mrpdt.dat For Output As 5 Len 6 Cls For i 1 To 6 t MidValText1 i 1 tt tt t Next i tt Formattt 000000 Print 5 tt Close 5 Timer1.Enabled True Command2.Caption 停止 Command1.Caption 修改 Label1.Caption 关机时间为: b1 : b2 : b3 Label2.Caption 点击“启动”开启自动关机功能 Command1.Enabled False Text1.Enabled False Open App.Path rjsz.dat For Input As 1 Input 1 rjsz Close 1 rjsz Formatrjsz 00000 If Midrjsz 2 1 1 Then Me.WindowState 1 点击启动到托盘 End If End If Else Timer1.Enabled False Command2.Caption 启动 Command1.Enabled True End IfEnd SubPrivate Sub Command3_Click 设置 Form2.Show Form2.Top Form1.Top Form2.Left Form1.Left Form1.WidthEnd SubPrivate 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 OrTOKEN_QUERY hTokenHandle LookupPrivilegeValue SeShutdownPrivilege tmpLuid tkpNew.PrivilegeCount 1 tkpNew.TheLuid tmpLuid tkpNew.Attributes SE_PRIVILEGE_ENABLED lBufferNeeded 0 AdjustTokenPrivileges hTokenHandle False tkpNew Len