Necesito saber con que codigo puedo apagar el equipo pero que sirva con windows XP y NT porque he recibido algunas respuestas que solo sirven para 98 95 y ME, gracias.
Puedes probar con el siguiente código: ------------------------------------------------------------------ '************************************************************************ En un modulo pega el siguiente codigo : '************************************************************************ Option Explicit ' Shutdown Flags Public Const EWX_LOGOFF = 0 Public Const EWX_SHUTDOWN = 1 Public Const EWX_REBOOT = 2 Public Const EWX_FORCE = 4 Public Const ANYSIZE_ARRAY = 1 Public Const SE_PRIVILEGE_ENABLED = &H2 Public Const TokenPrivileges = 3 Public Const TOKEN_ASSIGN_PRIMARY = &H1 Public Const TOKEN_DUPLICATE = &H2 Public Const TOKEN_IMPERSONATE = &H4 Public Const TOKEN_QUERY = &H8 Public Const TOKEN_QUERY_SOURCE = &H10 Public Const TOKEN_ADJUST_PRIVILEGES = &H20 Public Const TOKEN_ADJUST_GROUPS = &H40 Public Const TOKEN_ADJUST_DEFAULT = &H80 Public Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege" Type LARGE_INTEGER lowpart As Long highpart As Long End Type Type Luid lowpart As Long highpart As Long End Type Type LUID_AND_ATTRIBUTES 'pLuid As Luid pLuid As LARGE_INTEGER Attributes As Long End Type Type TOKEN_PRIVILEGES PrivilegeCount As Long Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES End Type 'Versión para 32 bits Declare Function ExitWindowsEx Lib "User32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long Declare Function InitiateSystemShutdown Lib "advapi32.dll" Alias "InitiateSystemShutdownA" (ByVal lpMachineName As String, ByVal lpMessage As String, ByVal dwTimeout As Long, ByVal bForceAppsClosed As Long, ByVal bRebootAfterShutdown As Long) As Long Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long Declare Function GetCurrentProcess Lib "kernel32" () As Long Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LARGE_INTEGER) As Long Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Declare Function GetLastError Lib "kernel32" () As Long #If Win32 Then Public Function InitiateShutdownMachine(ByVal Machine As String, _ Optional Force As Variant, Optional Restart As Variant, _ Optional AllowLocalShutdown As Variant, _ Optional Delay As Variant, _ Optional Message As Variant) As Boolean Dim hProc As Long Dim OldTokenStuff As TOKEN_PRIVILEGES Dim OldTokenStuffLen As Long Dim NewTokenStuff As TOKEN_PRIVILEGES Dim NewTokenStuffLen As Long Dim pSize As Long If IsMissing(Force) Then Force = False If IsMissing(Restart) Then Restart = True If IsMissing(AllowLocalShutdown) Then AllowLocalShutdown = False If IsMissing(Delay) Then Delay = 0 If IsMissing(Message) Then Message = "" If InStr(Machine, "\\") = 1 Then Machine = Right(Machine, Len(Machine) - 2) End If If (LCase(GetMyMachineName) = LCase(Machine)) Then If AllowLocalShutdown = False Then Exit Function If 0 = OpenProcessToken(GetCurrentProcess(), _ TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hProc) Then 'MsgBox "OpenProcessToken Error: " & GetLastError() Exit Function End If If 0 = LookupPrivilegeValue(vbNullString, SE_SHUTDOWN_NAME, _ OldTokenStuff.Privileges(0).pLuid) Then 'MsgBox "LookupPrivilegeValue Error: " & GetLastError() Exit Function End If NewTokenStuff = OldTokenStuff NewTokenStuff.PrivilegeCount = 1 NewToke