Foros del Web » Programación para mayores de 30 ;) » .NET »

Reiniciar, apagar, logout, suspender...

Estas en el tema de Reiniciar, apagar, logout, suspender... en el foro de .NET en Foros del Web. Buenas, me he encontrado una clase que permite resetear, apagar, deslogarse, suspender un servidor web. Imports System ' Import used for DLLImport Attribute Imports System.Runtime.InteropServices ...
  #1 (permalink)  
Antiguo 19/07/2005, 15:11
 
Fecha de Ingreso: enero-2004
Mensajes: 310
Antigüedad: 20 años, 3 meses
Puntos: 0
Reiniciar, apagar, logout, suspender...

Buenas, me he encontrado una clase que permite resetear, apagar, deslogarse, suspender un servidor web.

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
<StructLayout(LayoutKind.Sequential, Pack:=1)> _
Friend Structure Luid
Public Count As Integer
Public Luid As Long
Public Attr As Integer
End Structure 'TokPriv1Luid

' Lock Workstation
<DllImport("user32.dll", ExactSpelling:=True)> _
Function LockWorkStation() As Boolean
End Function

' Get Current Processes
<DllImport("kernel32.dll", ExactSpelling:=True)> _
Function GetCurrentProcess() As IntPtr
End Function

' Open Process Token
<DllImport("advapi32.dll", SetLastError:=True)> _
Function OpenProcessToken(ByVal h As IntPtr, ByVal acc As Integer, ByRef phtok As IntPtr) As Boolean
End Function

' Look up Priviledge Value
<DllImport("advapi32.dll", SetLastError:=True)> _
Friend Function LookupPrivilegeValue(ByVal host As String, ByVal name As String, ByRef pluid As Long) As Boolean
End Function

' Adjust Token Priviledges
<DllImport("advapi32.dll", ExactSpelling:=True, SetLastError:=True)> _
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
<DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)> _
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()

Espero que les sirva de ayuda
__________________
Un saludo,
Trucos
Videos
  #2 (permalink)  
Antiguo 19/07/2005, 15:47
 
Fecha de Ingreso: abril-2004
Ubicación: México D.F.
Mensajes: 1.724
Antigüedad: 20 años
Puntos: 4
Ojalá te pasen al foro .NET
  #3 (permalink)  
Antiguo 19/07/2005, 15:51
 
Fecha de Ingreso: enero-2004
Mensajes: 310
Antigüedad: 20 años, 3 meses
Puntos: 0
Es valido para asp.net y vb.net. Interpreto que el foro de asp tambien entra la tecnologia asp.net, nuse!
Si no es asi, sorry, ya me moveran a .net!
__________________
Un saludo,
Trucos
Videos
  #4 (permalink)  
Antiguo 19/07/2005, 15:51
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
porque no lo colocas en los fag's??
gracias por la funcion
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #5 (permalink)  
Antiguo 19/07/2005, 16:02
Avatar de El_Metallick  
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago, Chile
Mensajes: 1.718
Antigüedad: 21 años, 5 meses
Puntos: 16
puede servir alguna vez :P gracias saludos
__________________
Haz la guerra en la cama y el amor donde se te de la gana...
El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!!
  #6 (permalink)  
Antiguo 19/07/2005, 16:07
 
Fecha de Ingreso: abril-2004
Ubicación: México D.F.
Mensajes: 1.724
Antigüedad: 20 años
Puntos: 4
A ver que alguien me demuestra lo contrario usandolo en ASP.





QUIERO UN EJEMPLO :

asp= asp + asp.net

Ni en las faq's ni en nada solo al foro. net.
  #7 (permalink)  
Antiguo 19/07/2005, 17:24
 
Fecha de Ingreso: junio-2003
Ubicación: Asturias
Mensajes: 2.429
Antigüedad: 20 años, 10 meses
Puntos: 7
Ufff, una pena k use APIS . . . . .NET jamás llegará a ser multiplataforma ? :S
__________________
Charlie.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:27.