中文字幕日韩精品一区二区免费_精品一区二区三区国产精品无卡在_国精品无码专区一区二区三区_国产αv三级中文在线

vb.net關(guān)閉計(jì)算機(jī) vbs關(guān)閉程序的代碼

vb.net實(shí)現(xiàn)關(guān)機(jī)

這是點(diǎn)擊Option 你可以

創(chuàng)新互聯(lián)建站主要從事網(wǎng)站設(shè)計(jì)制作、成都做網(wǎng)站、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)新建,十余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):028-86922220

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

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

' 注銷當(dāng)前用戶

retval = ExitWindowsEx(EWX_FORCE, 0) bitsCN.Com

ElseIf Option2.Checked Then

' 關(guān)閉計(jì)算機(jī)

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é)束應(yīng)用程序

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 2005編寫定時關(guān)機(jī)程序

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

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

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

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

具體步驟如下

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

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

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

雙擊窗體進(jì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 注銷計(jì)算機(jī)Friend Const EWX_SHUTDOWN As Integer = H 關(guān)閉計(jì)算機(jī)Friend Const EWX_REBOOT As Integer = H 重新啟動計(jì)算機(jī)Friend Const EWX_FORCE As Integer = H 關(guān)閉所有進(jìn)程 注銷計(jì)算機(jī)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)用進(jìn)程值 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)) 重新啟動計(jì)算機(jī)End Sub

Public Shared Sub PowerOff() DoExitWin((EWX_FORCE Or EWX_POWEROFF)) 關(guān)閉計(jì)算機(jī)End Sub

Public Shared Sub LogoOff() DoExitWin((EWX_FORCE Or EWX_LOGOFF)) 注銷計(jì)算機(jī)End Sub

Dim entTime As Object 保存輸入時間Dim xianzaiTime As Object 保存實(shí)時時間Dim startTime As Object 保存開始定時時間

注銷button 按鈕輸入code

Private Sub Button _Click(ByVal sender As System Object

ByVal e As System EventArgs) Handles Button ClickLogoOff() 注銷計(jì)算機(jī)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)閉計(jì)算機(jī)按鈕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)閉計(jì)算機(jī)End Sub

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

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

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

進(jìn)入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 鍵運(yùn)行如圖 所示 選擇相應(yīng)選項(xiàng)后點(diǎn)擊(關(guān)閉計(jì)算機(jī)啟動定時器按鈕)就可以了 現(xiàn)在程序?qū)凑漳闼O(shè)定的時間而啟動關(guān)閉計(jì)算機(jī)選項(xiàng)

lishixinzhi/Article/program/net/201311/12366

vb.net關(guān)閉指定windowsname的頁面

使用VB.NET關(guān)閉指定WindowsName的頁面可以通過使用System.Diagnostics.Process類的Kill方法來完成。

Kill方法接受一個參數(shù),即要關(guān)閉的進(jìn)程的窗口名稱,該窗口名稱可以通過Process.GetProcessesByName函數(shù)獲得,這樣就可以遍歷找到任何一個指定的窗口名稱并將其關(guān)閉。例如:

Dim process As Process = Process.GetProcessesByName(“MyApplication.exe”)

process.Kill()

當(dāng)前名稱:vb.net關(guān)閉計(jì)算機(jī) vbs關(guān)閉程序的代碼
網(wǎng)頁地址:http://www.rwnh.cn/article46/doshseg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google網(wǎng)站維護(hù)、ChatGPT、域名注冊、定制開發(fā)外貿(mào)建站

廣告

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

成都seo排名網(wǎng)站優(yōu)化
延津县| 沾化县| 渭源县| 醴陵市| 永和县| 曲水县| 安溪县| 吉木萨尔县| 定南县| 汉中市| 那坡县| 浮梁县| 金山区| 闻喜县| 龙口市| 镇平县| 筠连县| 瑞丽市| 吴堡县| 裕民县| 顺昌县| 正镶白旗| 安塞县| 澳门| 天长市| 宁强县| 抚顺市| 介休市| 汉中市| 钦州市| 太康县| 开平市| 思茅市| 靖宇县| 汝阳县| 白沙| 芷江| 金川县| 炉霍县| 汝城县| 彰化市|