VB.NET中怎么实现定时关机
本篇文章给大家分享的是有关VB.NET中怎么实现定时关机,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
成都创新互联主要企业基础官网建设,电商平台建设,移动手机平台,重庆小程序开发等一系列专为中小企业专业公司产品体系;应对中小企业在互联网运营的各种问题,为中小企业在互联网的运营中保驾护航。
具体步骤如下:
首先在Form1窗体上添加一个Label1控件属性text设置为:今天:2.然后分别添加3个button控件name分别为button1、button2、button3它们的text属性分别为1. 关闭计算机(启动定时器)2. 注销3. 重新启动。
现在我们就需要为程序加上一个定时器了,这个定时器需要与textbox1控件相关联,输入正确时间格式后就可以启动定时功能了。然后我们需要在窗体上添加一个timer、一个textbox1控件、和一个RadioButton1控件。让它们保留默认值不变。其中. TextBox1控件的text属性设置为:00:00:00 。RadioButton1控件text设置为:指定时间关机|时间格式:00小时:00分钟:00秒
双击窗体进入常规-声明Public Class Form1 事件中。以上介绍VB.NET实现定时关机
Imports System.Runtime.InteropServices Imports Microsoft.VisualBasic Public Class Form1 '调用系统参数 Friend Shared Function GetCurrentProcess() As IntPtr End Function Friend Shared Function OpenProcessToken(ByVal h As IntPtr, ByVal acc As Integer, ByRef phtok As IntPtr) As Boolean End Function Friend Shared Function LookupPrivilegeValue(ByVal host As String, ByVal name As String, ByRef pluid As Long) As Boolean End Function Friend Shared Function AdjustTokenPrivileges(ByVal htok As IntPtr, ByVal disall As Boolean, ByRef newst As TokPriv1Luid, ByVal len As Integer, ByVal prev As IntPtr, ByVal relen As IntPtr) As Boolean End Function Friend Shared Function ExitWindowsEx(ByVal flg As Integer, ByVal rea As Integer) As Boolean End Function Friend Const SEPRIVILEGEENABLED As Integer = &H2 Friend Const TOKENQUERY As Integer = &H8 Friend Const TOKENADJUSTPRIVILEGES As Integer = &H20 Friend Const SESHUTDOWNNAME As String = "SeShutdownPrivilege" Friend Const EWXLOGOFF As Integer = &H0 '注销计算机 Friend Const EWXSHUTDOWN As Integer = &H1'关闭计算机 Friend Const EWXREBOOT As Integer = &H2'重新启动计算机 Friend Const EWXFORCE As Integer = &H4'关闭所有进程,注销计算机 Friend Const EWXPOWEROFF As Integer = &H8 Friend Const EWXFORCEIFHUNG As Integer = &H10 '引用参数 Friend Structure TokPriv1Luid Public Count As Integer Public Luid As Long Public Attr As Integer End Structure Private Shared Sub DoExitWin(ByVal flg As Integer) Dim xc As Boolean '判断语句 Dim tp As TokPriv1Luid Dim hproc As IntPtr = GetCurrentProcess() '调用进程值 Dim htok As IntPtrIntPtr = IntPtr.Zero xc = OpenProcessToken(hproc, TOKENADJUSTPRIVILEGES Or TOKENQUERY, htok) tp.Count = 1 tp.Luid = 0 tp.Attr = SEPRIVILEGEENABLED xc = LookupPrivilegeValue(Nothing, SESHUTDOWNNAME, tp.Luid) xc = AdjustTokenPrivileges(htok, False, tp, 0, IntPtr.Zero, IntPtr.Zero) xc = ExitWindowsEx(flg, 0) End Sub Public Shared Sub Reboot() DoExitWin((EWXFORCE Or EWXREBOOT)) '重新启动计算机 End Sub Public Shared Sub PowerOff() DoExitWin((EWXFORCE Or EWXPOWEROFF)) '关闭计算机 End Sub Public Shared Sub LogoOff() DoExitWin((EWXFORCE Or EWXLOGOFF)) '注销计算机 End Sub Dim entTime As Object '保存输入时间 Dim xianzaiTime As Object '保存实时时间 Dim startTime As Object '保存开始定时时间
以上就是VB.NET中怎么实现定时关机,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。
网页标题:VB.NET中怎么实现定时关机
路径分享:http://hbruida.cn/article/jjhcsc.html