Los mejores
trucos de informática
y
trucos de programación
.
Inicio
Trucos de Windows
Foros de informática
Informáticos
Nosotros
Registrar
Menú Privado
Trucos Windows
Trucos de Windows 7
Trucos de Windows Vista
Trucos de Windows XP
Windows 2003 Server
Trucos de Messenger
Trucos de Office
Trucos de Redes
Trucos Programación
Visual Basic.NET
Visual Basic 6
Trucos C#
Trucos ASP.NET
Trucos ASP.NET 2.0
SQL Server 2000
SQL Server 2005
Javascript
Trucos CSS
Otros Trucos
Trucos de SEO
Posicionar una web
Trucos de Google
Trucos Hardware
Varios
Nosotros
Webs recomendadas
Videos
Videos de humor
Trucos
Animales
Baja de Jazztel
<< Truco Anterior
Siguiente truco >>
Enlaces patrocinados:
Trucos de ASP.NET
Clase para Reiniciar, apagar, suspender, deslogar el servidor web
Esta clase permite reiniciar, apagar o suspender el servidor web (Válido para aplicaciones web y de escritorio)
Imports System
' Import used for DLLImport Attribute
Imports System.Runtime.InteropServices
Module modToken
' Constants
Const SE_PRIVILEGE_ENABLED As Integer = &H2
Const TOKEN_QUERY As Integer = &H8
Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20
Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege"
' Exit Windows Constants
Const EWX_LOGOFF As Integer = &H0
Const EWX_SHUTDOWN As Integer = &H1
Const EWX_REBOOT As Integer = &H2
Const EWX_FORCE As Integer = &H4
Const EWX_POWEROFF As Integer = &H8
Const EWX_FORCEIFHUNG As Integer = &H10
'Structure
_
Friend Structure Luid
Public Count As Integer
Public Luid As Long
Public Attr As Integer
End Structure 'TokPriv1Luid
' Lock Workstation
_
Function LockWorkStation() As Boolean
End Function
' Get Current Processes
_
Function GetCurrentProcess() As IntPtr
End Function
' Open Process Token
_
Function OpenProcessToken(ByVal h As IntPtr, ByVal acc As Integer, ByRef phtok As IntPtr) As Boolean
End Function
' Look up Priviledge Value
_
Friend Function LookupPrivilegeValue(ByVal host As String, ByVal name As String, ByRef pluid As Long) As Boolean
End Function
' Adjust Token Priviledges
_
Friend Function AdjustTokenPrivileges(ByVal htok As IntPtr, ByVal disall As Boolean, ByRef newst As Luid, ByVal len As Integer, ByVal prev As IntPtr, ByVal relen As IntPtr) As Boolean
End Function
' Exit Windows
_
Friend Function ExitWindowsEx(ByVal flg As Integer, ByVal rea As Integer) As Boolean
End Function
' Exit Windows Sub
Private Sub DoExitWindows(ByVal flg As Integer)
Dim tp As Luid
Dim hproc As IntPtr = GetCurrentProcess()
Dim htok As IntPtr = IntPtr.Zero
OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, htok)
tp.Count = 1
tp.Luid = 0
tp.Attr = SE_PRIVILEGE_ENABLED
LookupPrivilegeValue(Nothing, SE_SHUTDOWN_NAME, tp.Luid)
AdjustTokenPrivileges(htok, False, tp, 0, IntPtr.Zero, IntPtr.Zero)
ExitWindowsEx(flg, 0)
End Sub
' Shutdown
Public Sub Shutdown()
DoExitWindows(EWX_SHUTDOWN)
End Sub
' Restart
Public Sub Restart()
DoExitWindows(EWX_REBOOT Or EWX_FORCE)
End Sub
' Log off
Public Sub LogOff()
DoExitWindows(EWX_LOGOFF)
End Sub
' Lock Workstation
Public Sub LockTheComputer()
LockWorkStation()
End Sub
End Module
Funciones:
Shutdown()
Restart()
LogOff()
LockTheComputer()
Pon el truco en tus favoritos
NUEVO:
Si tienes dudas de informática pregunta en nuestros foros
Compartir en:
Dejar un comentario
Nombre:
Mail:
Web:
Comentario:
Código de seguridad
Inserta el código de seguridad
Contactar con mistrucos.net