本篇文章給大家分享的是有關(guān)VB.NET中怎么實(shí)現(xiàn)定時(shí)關(guān)機(jī),小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
成都創(chuàng)新互聯(lián)主要企業(yè)基礎(chǔ)官網(wǎng)建設(shè),電商平臺(tái)建設(shè),移動(dòng)手機(jī)平臺(tái),重慶小程序開發(fā)等一系列專為中小企業(yè)專業(yè)公司產(chǎn)品體系;應(yīng)對(duì)中小企業(yè)在互聯(lián)網(wǎng)運(yùn)營的各種問題,為中小企業(yè)在互聯(lián)網(wǎng)的運(yùn)營中保駕護(hù)航。
具體步驟如下:
首先在Form1窗體上添加一個(gè)Label1控件屬性text設(shè)置為:今天:2.然后分別添加3個(gè)button控件name分別為button1、button2、button3它們的text屬性分別為1. 關(guān)閉計(jì)算機(jī)(啟動(dòng)定時(shí)器)2. 注銷3. 重新啟動(dòng)。
現(xiàn)在我們就需要為程序加上一個(gè)定時(shí)器了,這個(gè)定時(shí)器需要與textbox1控件相關(guān)聯(lián),輸入正確時(shí)間格式后就可以啟動(dòng)定時(shí)功能了。然后我們需要在窗體上添加一個(gè)timer、一個(gè)textbox1控件、和一個(gè)RadioButton1控件。讓它們保留默認(rèn)值不變。其中. TextBox1控件的text屬性設(shè)置為:00:00:00 。RadioButton1控件text設(shè)置為:指定時(shí)間關(guān)機(jī)|時(shí)間格式:00小時(shí):00分鐘:00秒
雙擊窗體進(jìn)入常規(guī)-聲明Public Class Form1 事件中。以上介紹VB.NET實(shí)現(xiàn)定時(shí)關(guān)機(jī)
Imports System.Runtime.InteropServices Imports Microsoft.VisualBasic Public Class Form1 '調(diào)用系統(tǒng)參數(shù) 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 '注銷計(jì)算機(jī) Friend Const EWXSHUTDOWN As Integer = &H1'關(guān)閉計(jì)算機(jī) Friend Const EWXREBOOT As Integer = &H2'重新啟動(dòng)計(jì)算機(jī) Friend Const EWXFORCE As Integer = &H4'關(guān)閉所有進(jìn)程,注銷計(jì)算機(jī) Friend Const EWXPOWEROFF As Integer = &H8 Friend Const EWXFORCEIFHUNG As Integer = &H10 '引用參數(shù) 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() '調(diào)用進(jìn)程值 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)) '重新啟動(dòng)計(jì)算機(jī) End Sub Public Shared Sub PowerOff() DoExitWin((EWXFORCE Or EWXPOWEROFF)) '關(guān)閉計(jì)算機(jī) End Sub Public Shared Sub LogoOff() DoExitWin((EWXFORCE Or EWXLOGOFF)) '注銷計(jì)算機(jī) End Sub Dim entTime As Object '保存輸入時(shí)間 Dim xianzaiTime As Object '保存實(shí)時(shí)時(shí)間 Dim startTime As Object '保存開始定時(shí)時(shí)間
以上就是VB.NET中怎么實(shí)現(xiàn)定時(shí)關(guān)機(jī),小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
本文題目:VB.NET中怎么實(shí)現(xiàn)定時(shí)關(guān)機(jī)
標(biāo)題網(wǎng)址:http://jinyejixie.com/article32/jjhcsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、服務(wù)器托管、關(guān)鍵詞優(yōu)化、建站公司、微信公眾號(hào)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)