vb.net關(guān)機命令 vba關(guān)機代碼

VB.NET怎樣設(shè)計定時關(guān)機

1、開機進入桌面后,按下“Windows徽標鍵+I”鍵,選中并打開“控制面板”

創(chuàng)新互聯(lián)于2013年創(chuàng)立,先為清水河等服務建站,清水河等地企業(yè),進行企業(yè)商務咨詢服務。為清水河企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。

2、在“控制面板”中的“系統(tǒng)和安全”里,選中“管理工具”里的“計劃任務”,并打開“計劃任務”

3、在“任務計劃程序”里,打開“創(chuàng)建任務”

4、在“創(chuàng)建任務”的“常規(guī)”中,根據(jù)相應需求設(shè)置,比如“名稱:定時關(guān)機”

5、在“創(chuàng)建任務”的“觸發(fā)器”中,點“新建”,并在“新建觸發(fā)器”中,根據(jù)相應需求設(shè)置后,點“確定”

6、在“創(chuàng)建任務”的“操作”中,點“新建”,并在“新建操作”中的“程序或腳本”里,根據(jù)下圖依次輸入“shutdown”和“-s”后,“點“確定”

7、在“創(chuàng)建任務”的“條件”中,根據(jù)相應需求設(shè)置

8、在“創(chuàng)建任務”的“設(shè)置”中,根據(jù)相應需求設(shè)置后,點“確定”

9、這時“定時關(guān)機”的任務已創(chuàng)建完成!

VB.NET 2005編寫定時關(guān)機程序

最近在網(wǎng)上搜索了一些關(guān)于實現(xiàn)關(guān)機 重啟 注銷的文章 發(fā)現(xiàn)大多介紹的是VB NET 用API實現(xiàn)這些功能 且在XPsp 環(huán)境下無法正常的關(guān)機與注銷 而對于VB NET 的介紹幾乎沒有 本文章所涉及的知識點有

用實現(xiàn)關(guān)機 重啟 注銷功能 通過使用textbox與timer控件的結(jié)合編寫定時器功能 為你的程序加上超鏈接

本篇文章具有一定的基礎(chǔ)性和廣泛的實用性 相信能夠給 初學者帶來一定的幫助

本文所使用的編程環(huán)境是Microsoft Visual Studio 首先打開 Visual Studio 在文件 (File) 菜單上 單擊新建項目 (New Project) 在新建項目 (New Project) 對話框的模板 (Templates) 窗格中 單擊 Windows 應用程序 (Windows Application) 單擊確定 (OK)

具體步驟如下

首先在Form 窗體上添加一個Label 控件屬性text設(shè)置為:今天: 然后分別添加 個button控件name分別為button button button 它們的text屬性分別為 關(guān)閉計算機(啟動定時器) 注銷 重新啟動

現(xiàn)在我們就需要為程序加上一個定時器了 這個定時器需要與textbox 控件相關(guān)聯(lián) 輸入正確時間格式后就可以啟動定時功能了 然后我們需要在窗體上添加一個timer 一個textbox 控件 和一個RadioButton 控件 讓它們保留默認值不變 其中 TextBox 控件的text屬性設(shè)置為 : : RadioButton 控件text設(shè)置為 指定時間關(guān)機|時間格式 小時: 分鐘: 秒如圖 所示

以上界面工作基本完成現(xiàn)在需要輸入代碼了

雙擊窗體進入常規(guī) 聲明Public Class Form 事件中

CODE

Imports System Runtime InteropServicesImports Microsoft VisualBasicPublic Class Form _ 調(diào)用系統(tǒng)參數(shù)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 關(guān)閉計算機Friend Const EWX_REBOOT As Integer = H 重新啟動計算機Friend Const EWX_FORCE As Integer = H 關(guān)閉所有進程 注銷計算機Friend Const EWX_POWEROFF As Integer = H Friend Const EWX_FORCEIFHUNG As Integer = H

_  引用參數(shù) 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()  調(diào)用進程值 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)) 關(guān)閉計算機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

雙擊關(guān)閉計算機按鈕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函數(shù)判斷輸入的時間格式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函數(shù)判斷是否到時間了

End IfEnd If

PowerOff() 關(guān)閉計算機End Sub

好了 基本上一個定時關(guān)機程序就完成了 接下來加一個超級鏈接吧!當然對于高手來說可能是廢話 但是對于新手來說這也是必備的 這個超級鏈接當然是我們最喜歡的天極網(wǎng)開發(fā)頻道了

先創(chuàng)建一個Label控件吧 把它托到窗體上 將text屬性設(shè)置為天極網(wǎng)開發(fā)頻道如圖

接下來需要輸入代碼了 雙擊窗體Form

進入Public Class Form 事件

代碼

Private Declare Function ShellExecute Lib shell dll

Alias ShellExecuteA (ByVal hwngnd As Integer

ByVal lpOperation As String ByVal lpFile As String

ByVal lpParameters As String ByVal lpDirectory As String

ByVal nShowCmd As Integer) As Integer

如圖

雙擊剛才添加的label屬性text:(天極網(wǎng)開發(fā)頻道)中輸入以下代碼

Private Sub Label _Click(ByVal sender As System Object

ByVal e As System EventArgs) Handles Label ClickShellExecute( open CStr( ) CStr( ) )

End SubEnd Class

OK!全部搞定 按F 鍵運行如圖 所示 選擇相應選項后點擊(關(guān)閉計算機啟動定時器按鈕)就可以了 現(xiàn)在程序?qū)凑漳闼O(shè)定的時間而啟動關(guān)閉計算機選項

lishixinzhi/Article/program/net/201311/12366

vb.net WinXP/2000操作系統(tǒng)自動關(guān)機的實現(xiàn)

Windows

XP的關(guān)機是由Shutdown.exe程序來控制的,位于Windows\System32文件夾中。如果想讓Windows

2000也實現(xiàn)同樣的效果,可以把Shutdown.exe復制到系統(tǒng)目錄下。

比如你的電腦要在22:00關(guān)機,可以選擇“開始→運行”,輸入“at

22:00

Shutdown

-s”,這樣,到了22點電腦就會出現(xiàn)“系統(tǒng)關(guān)機”對話框,默認有30秒鐘的倒計時并提示你保存工作。如果你想以倒計時的方式關(guān)機,可以輸入“Shutdown.exe

-s

-t

3600”,這里表示60分鐘后自動關(guān)機,“3600”代表60分鐘。

設(shè)置好自動關(guān)機后,如果想取消的話,可以在運行中輸入“shutdown

-a”。另外輸入“shutdown

-i”,則可以打開設(shè)置自動關(guān)機對話框,對自動關(guān)機進行設(shè)置。

Shutdown.exe的參數(shù),每個都具有特定的用途,執(zhí)行每一個都會產(chǎn)生不同的效果,比如“-s”就表示關(guān)閉本地計算機,“-a”表示取消關(guān)

機操作,下面列出了更多參數(shù),大家可以在Shutdown.exe中按需使用。

其他的我也不多說了,這樣說已經(jīng)很詳細了,你應該能看懂。

請問VB.NET的關(guān)機語句是?

這是點擊Option 你可以

用個msgbox函數(shù) 點擊YES時候運行關(guān)機代碼即可

Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer 

Const EWX_FORCE As Short = 4

Const EWX_LOGOFF As Short = 0

Const EWX_REBOOT As Short = 2

Const EWX_SHUTDOWN As Short = 1

Dim retval As Integer

' 定義Esc按鍵

Const VK_ESCAPE As Short = H1Bs

Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click

If Option1.Checked Then

' 注銷當前用戶

retval = ExitWindowsEx(EWX_FORCE, 0) bitsCN.Com

ElseIf Option2.Checked Then

' 關(guān)閉計算機

retval = ExitWindowsEx(EWX_SHUTDOWN, 0)

ElseIf Option3.Checked Then

' 重新啟動

retval = ExitWindowsEx(EWX_REBOOT, 0)

End If

End Sub

Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click

Me.Close()

End Sub

' 按Esc鍵時,結(jié)束應用程序

Private Sub Form1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

If KeyAscii = VK_ESCAPE Then BBS.bitsCN.com網(wǎng)管論壇

Me.Close()

End If

If KeyAscii = 0 Then

eventArgs.Handled = True

End If

End Sub

分享名稱:vb.net關(guān)機命令 vba關(guān)機代碼
網(wǎng)址分享:http://muchs.cn/article20/doeecco.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)網(wǎng)站維護、營銷型網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)做網(wǎng)站、全網(wǎng)營銷推廣

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設(shè)