当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > "关机/休眠/重启/注销"的类

ASP.NET
DVNEWS 3.2 1013版免虚拟目录的安装方法,只要三个步骤
DataRow的序列化问题
VB.net基础:使用UDP发送和接收消息
采用HttpModules来重写URLs(实践篇)
要用到事务了
DataGrid中单元格的比较
动态引用WebService,建立WebService虚拟机
[初学VB.NET]数据绑定
使用ASP调用WebService时不能以Name为数据库中的字段
在VB.NET里操作文本文件
web下打印的办法
怎样把SQL_SERVER数据库里的(类型是image)图片显示在aspx页面里的image控件里
C#中字符串的加密
中小企业信息应用的利器:DAP-Dynamic Applications Platform
数据库系统概论学习笔记
体会到译者的艰辛,也发现了他们犯的错误
IISManager V1.1 是一个在线管理IIS,维护站点组件,安全稳定,最重要的是完全免费。
VS FlexGridPro 8.0如何在window98运行---有没有升级版本,急请高手指点
给立方体添加纹理
Wrox的C#高级编程第三版第一部分第一章(1~9页)

ASP.NET 中的 "关机/休眠/重启/注销"的类


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 37 ::
收藏到网摘: n/a

Imports SystemImports System.TextImports System.DiagnosticsImports System.Runtime.InteropServicesPublic Class ExitWindwos Public Enum RestartOptions LogOff = 0 PowerOff = 8 Reboot = 2 ShutDown = 1 Suspend = -1 Hibernate = -2 'EWX_FORCE = 4 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 Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As IntPtr Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As IntPtr) As Integer Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As IntPtr, ByVal lpProcName As String) As IntPtr Private Declare Function SetSuspendState Lib "Powrprof" (ByVal Hibernate As Integer, ByVal ForceCritical As Integer, ByVal DisableWakeEvent As Integer) As Integer Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As IntPtr, ByVal DesiredAccess As Integer, ByRef TokenHandle As IntPtr) As Integer Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, ByRef lpLuid As LUID) As Integer Private 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 Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer Private 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 Private 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 Private 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 Private 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 Private Sub SuspendSystem(ByVal hibernate As Boolean, ByVal force As Boolean) If Not CheckEntryPoint("powrprof.dll", "SetSuspendStat