vb.net

位置:IT落伍者 >> vb.net >> 浏览文章

用VB.NET 2005编写定时关机程序[2]


发布日期:2024年01月29日
 
用VB.NET 2005编写定时关机程序[2]

双击窗体进入常规声明Public Class Form 事件中

CODE:

Imports SystemRuntimeInteropServices

Imports MicrosoftVisualBasic

Public Class Form

<DllImport(kerneldll ExactSpelling:=True)> _调用系统参数

Friend Shared Function GetCurrentProcess() As IntPtr

End Function

<DllImport(advapidll ExactSpelling:=True SetLastError:=True)> _

Friend Shared Function OpenProcessToken(ByVal h As IntPtr ByVal acc As Integer ByRef phtok As IntPtr) As Boolean

End Function

<DllImport(advapidll SetLastError:=True)> _

Friend Shared Function LookupPrivilegeValue(ByVal host As String ByVal name As String ByRef pluid As Long) As Boolean

End Function

<DllImport(advapidll ExactSpelling:=True SetLastError:=True)> _

Friend Shared Function AdjustTokenPrivileges(ByVal htok As IntPtr ByVal disall As Boolean ByRef newst As TokPrivLuid ByVal len As Integer ByVal prev As IntPtr ByVal relen As IntPtr) As Boolean

End Function

<DllImport(userdll ExactSpelling:=True SetLastError:=True)> _

Friend Shared Function ExitWindowsEx(ByVal flg As Integer ByVal rea As Integer) As Boolean

End 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关闭计算机

Friend Const EWX_REBOOT As Integer = &H重新启动计算机

Friend Const EWX_FORCE As Integer = &H关闭所有进程注销计算机

Friend Const EWX_POWEROFF As Integer = &H

Friend Const EWX_FORCEIFHUNG As Integer = &H

<StructLayout(LayoutKindSequential Pack:=)> _

引用参数

Friend Structure TokPrivLuid

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 TokPrivLuid

Dim hproc As IntPtr = GetCurrentProcess()

调用进程值

Dim htok As IntPtr = IntPtrZero

xc = OpenProcessToken(hproc TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY htok)

tpCount =

tpLuid =

tpAttr = SE_PRIVILEGE_ENABLED

xc = LookupPrivilegeValue(Nothing SE_SHUTDOWN_NAME tpLuid)

xc = AdjustTokenPrivileges(htok False tp IntPtrZero IntPtrZero)

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)) 关闭计算机

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 保存开始定时时间

[] [] [] []

               

上一篇:用VB.NET 2005编写定时关机程序[1]

下一篇:用VB.NET 2005编写定时关机程序[3]