vb.net禁止休眠 vbs休眠

vb.net2008攔截關(guān)機(jī)或注銷消息

在SystemEvents類中 可以 用戶試圖注銷或關(guān)閉系統(tǒng)時(shí)發(fā)生。 (當(dāng)用戶試圖注銷或關(guān)閉系統(tǒng)時(shí)發(fā)生。當(dāng)用戶試圖注銷或關(guān)閉系統(tǒng)時(shí)發(fā)生。) 這個(gè) 事件處理函數(shù)中 可以找到如下方法

成都創(chuàng)新互聯(lián)公司長(zhǎng)期為上千余家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為二連浩特企業(yè)提供專業(yè)的成都做網(wǎng)站、網(wǎng)站制作,二連浩特網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

Private Shared WM_QUERYENDSESSION As Integer = H11

Private Shared systemShutdown As Boolean = False

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

If m.Msg = WM_QUERYENDSESSION Then

'MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot")

systemShutdown = True

End If

' If this is WM_QUERYENDSESSION, the closing event should be raised in the base WndProc.

MyBase.WndProc(m)

End Sub 'WndProc

Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

If (systemShutdown) Then

' Reset the variable because the user might cancel the shutdown.

systemShutdown = False

If (System.Windows.Forms.DialogResult.Yes = _

MessageBox.Show("My application", "Do you want to save your work before logging off?", MessageBoxButtons.YesNo)) Then

e.Cancel = True

Else

e.Cancel = False

End If

End If

End Sub

vb.net中如何禁止從任務(wù)欄關(guān)閉window

綁定窗體的FormClosing事件,執(zhí)行e.Cancel = True即可。

如果你不想在任務(wù)欄上顯示窗體,把窗體的ShowOnTaskbar設(shè)為False。

VB.net 多線程,導(dǎo)致無法響應(yīng)

t.Suspend() 這個(gè)是掛起線程。是一個(gè)異步方法。

t.Sleep 我看了是一個(gè)同步方法。要等這個(gè)方法運(yùn)行完了才繼續(xù)下一步。

這和from.show和 from.showdiaglog區(qū)別差不多!

至于疑問2我也沒找到原因。

求計(jì)算機(jī)休眠代碼

VB.NET中實(shí)現(xiàn)"關(guān)機(jī)/休眠/重啟/注銷"的類Imports System

Imports System.Text

Imports System.Diagnostics

Imports System.Runtime.InteropServices

Public Class WindowsController

Public Enum RestartOptions

LogOff = 0

PowerOff = 8

Reboot = 2

ShutDown = 1

Suspend = -1

Hibernate = -2

End Enum

Public Structure LUID

Dim LowPart As Integer

Dim HighPart As Integer

End Structure

Public Structure LUID_AND_ATTRIBUTES

Dim pLuid As LUID

Dim Attributes As Integer

End Structure

Public Structure TOKEN_PRIVILEGES

Dim PrivilegeCount As Integer

Dim Privileges As LUID_AND_ATTRIBUTES

End Structure

Private Const TOKEN_ADJUST_PRIVILEGES = H20

Private Const TOKEN_QUERY = H8

Private Const SE_PRIVILEGE_ENABLED = H2

Private Const FORMAT_MESSAGE_FROM_SYSTEM = H1000

Private Const EWX_FORCE = 4

Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As IntPtr

Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As IntPtr) As Integer

Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As IntPtr, ByVal lpProcName As String) As IntPtr

Declare Function SetSuspendState Lib "Powrprof" (ByVal Hibernate As Integer, ByVal ForceCritical As Integer, ByVal DisableWakeEvent As Integer) As Integer

Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As IntPtr, ByVal DesiredAccess As Integer, ByRef TokenHandle As IntPtr) As Integer

Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, ByRef lpLuid As LUID) As Integer

Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As IntPtr, ByVal DisableAllPrivileges As Integer, ByRef NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Integer, ByRef PreviousState As TOKEN_PRIVILEGES, ByRef ReturnLength As Integer) As Integer

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

Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Integer, ByVal lpSource As IntPtr, ByVal dwMessageId As Integer, ByVal dwLanguageId As Integer, ByVal lpBuffer As StringBuilder, ByVal nSize As Integer, ByVal Arguments As Integer) As Integer

Public Sub ExitWindows(ByVal how As RestartOptions, ByVal force As Boolean)

Select Case how

Case RestartOptions.Suspend

SuspendSystem(False, force)

Case RestartOptions.Hibernate

SuspendSystem(True, force)

Case Else

ExitWindows(Convert.ToInt32(how), force)

End Select

End Sub

Protected Sub ExitWindows(ByVal how As Integer, ByVal force As Boolean)

EnableToken("SeShutdownPrivilege")

If force Then how = how Or EWX_FORCE

If (ExitWindowsEx(how, 0) = 0) Then Throw New PrivilegeException(FormatError(Marshal.GetLastWin32Error()))

End Sub

Protected Sub EnableToken(ByVal privilege As String)

If Not CheckEntryPoint("advapi32.dll", "AdjustTokenPrivileges") Then Return

Dim tokenHandle As IntPtr = IntPtr.Zero

Dim privilegeLUID = New LUID()

Dim newPrivileges = New TOKEN_PRIVILEGES()

Dim tokenPrivileges As TOKEN_PRIVILEGES

If (OpenProcessToken(Process.GetCurrentProcess().Handle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, tokenHandle)) = 0 Then Throw New PrivilegeException(FormatError(Marshal.GetLastWin32Error()))

If (LookupPrivilegeValue("", privilege, privilegeLUID)) = 0 Then Throw New PrivilegeException(FormatError(Marshal.GetLastWin32Error()))

tokenPrivileges.PrivilegeCount = 1

tokenPrivileges.Privileges.Attributes = SE_PRIVILEGE_ENABLED

tokenPrivileges.Privileges.pLuid = privilegeLUID

Dim Size As Integer = 4

If (AdjustTokenPrivileges(tokenHandle, 0, tokenPrivileges, 4 + (12 * tokenPrivileges.PrivilegeCount), newPrivileges, Size)) = 0 Then Throw New PrivilegeException(FormatError(Marshal.GetLastWin32Error()))

End Sub

Protected Sub SuspendSystem(ByVal hibernate As Boolean, ByVal force As Boolean)

If Not CheckEntryPoint("powrprof.dll", "SetSuspendState") Then Throw New PlatformNotSupportedException("The SetSuspendState method is not supported on this system!")

SetSuspendState(Convert.ToInt32(IIf(hibernate, 1, 0)), Convert.ToInt32(IIf(force, 1, 0)), 0)

End Sub

Protected Function CheckEntryPoint(ByVal library As String, ByVal method As String) As Boolean

Dim libPtr As IntPtr = LoadLibrary(library)

If Not libPtr.Equals(IntPtr.Zero) Then

If Not GetProcAddress(libPtr, method).Equals(IntPtr.Zero) Then

FreeLibrary(libPtr)

Return True

End If

FreeLibrary(libPtr)

End If

Return False

End Function

Protected Function FormatError(ByVal number As Integer) As String

Dim Buffer = New StringBuilder(255)

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, IntPtr.Zero, number, 0, Buffer, Buffer.Capacity, 0)

Return Buffer.ToString()

End Function

End Class

Public Class PrivilegeException

Inherits Exception

Public Sub New()

MyBase.New()

End Sub

Public Sub New(ByVal message As String)

MyBase.New(message)

End Sub

End Class

例如實(shí)現(xiàn)注銷功能:

Dim shutdown As New WindowsController()

shutdown.ExitWindows(shutdown.RestartOptions.LogOff, False

vb.net里面怎么沒有sleep啊

它在System.Threading命名空間的Thread類中定義了

直接用 System.Threading.Thread.Sleep()方法

System.Threading.Thread.Sleep(time )‘time為整數(shù),單位毫秒

求助:VB.NET中線程的休眠時(shí)間最長(zhǎng)是多少

設(shè)定Timer象間觸發(fā)事件再給handler發(fā)消息處理行處理完重置timer間進(jìn)入循環(huán)即隨便用wait類土辦容易系統(tǒng)判定進(jìn)程掛死kill

分享題目:vb.net禁止休眠 vbs休眠
文章鏈接:http://m.kartarina.com/article4/hjjdie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航App開發(fā)Google做網(wǎng)站App設(shè)計(jì)網(wǎng)站建設(shè)

廣告

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

成都做網(wǎng)站
主站蜘蛛池模板: 国产精品无码一本二本三本色| 无码人妻精品一区二区三区蜜桃| 精品无码中出一区二区| 无码人妻啪啪一区二区| av无码aV天天aV天天爽| 国产精品三级在线观看无码| 久久久久久亚洲Av无码精品专口| 中文无码字幕中文有码字幕| 久久久久亚洲?V成人无码| 无码AV波多野结衣久久| 亚洲高清无码综合性爱视频| 日韩爆乳一区二区无码| 久久久久久国产精品无码下载| 亚洲AV无码乱码在线观看代蜜桃| 亚洲AⅤ永久无码精品AA| 亚洲AV成人噜噜无码网站| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 中国无码人妻丰满熟妇啪啪软件| 日韩精品无码熟人妻视频| 成人免费无码H在线观看不卡| 亚洲av中文无码字幕色不卡| 亚洲AV无码一区二区三区系列| 国外AV无码精品国产精品| 亚洲熟妇无码AV| 精品无码人妻一区二区三区品| 久久精品无码一区二区三区| 亚洲精品无码专区久久同性男| 久久久无码精品午夜| 无码里番纯肉h在线网站| 久久精品国产亚洲AV无码娇色 | 一本一道VS无码中文字幕| 国产50部艳色禁片无码| 人妻无码人妻有码中文字幕| 久久天堂av综合色无码专区| 97无码免费人妻超级碰碰碰碰 | 亚洲大尺度无码无码专线一区 | 无码中文字幕日韩专区| 亚洲AV无码一区二区乱孑伦AS| 亚洲日韩激情无码一区| 国产午夜精华无码网站| 亚洲中文久久精品无码ww16|