Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Littl3 en 22 Mayo 2008, 10:11 am



Título: Suspender pc desde VB
Publicado por: Littl3 en 22 Mayo 2008, 10:11 am
Buenas estado buscando como suspender el pc desde VB en google y solo encontrado como apagarlo/reiniciarlo utilizando las APIs pero no como suspenderlo, alguien me puede orientar un poco?


Título: Re: Suspender pc desde VB
Publicado por: seba123neo en 22 Mayo 2008, 14:49 pm
Hola,yo tengo aca un codigo que use en un programa para apagar el monitor..pero lo que hace realmente es suspender la pc y dejarla en standby digamos y al mover el mouse se reestablece todo,pero a algunos tambien los desconectaba de intenet..pero a mi no me paso...lo hace a travez de api's pero con Token Privileges..no se si te sirva...

saludos.


Título: Re: Suspender pc desde VB
Publicado por: SERBice en 26 Mayo 2008, 05:15 am
Api Guide:

Para saber si esta permitido el hibernado, apagado y/o suspendido:
Código
  1. Private Declare Function IsPwrShutdownAllowed Lib "Powrprof.dll" () As Long
  2. Private Declare Function IsPwrSuspendAllowed Lib "Powrprof.dll" () As Long
  3. Private Declare Function IsPwrHibernateAllowed Lib "Powrprof.dll" () As Long
  4. Private Sub Form_Load()
  5.    'KPD-Team 2001
  6.    'URL: http://www.allapi.net/
  7.    'E-Mail: KPDTeam@allapi.net
  8.    Debug.Print "Shutdown Allowed: " + CStr(CBool(IsPwrShutdownAllowed))
  9.    Debug.Print "Suspend Allowed: " + CStr(CBool(IsPwrSuspendAllowed))
  10.    Debug.Print "Hibernate Allowed: " + CStr(CBool(IsPwrHibernateAllowed))
  11. End Sub
  12.  

Windows 98 o posterior.



Mas codigo de Api Guide:
Código
  1. Private Const ANYSIZE_ARRAY = 1
  2. Private Const TOKEN_ADJUST_PRIVILEGES = &H20
  3. Private Const TOKEN_QUERY = &H8
  4. Private Const SE_PRIVILEGE_ENABLED = &H2
  5. Private Type LUID
  6.    LowPart As Long
  7.    HighPart As Long
  8. End Type
  9. Private Type LUID_AND_ATTRIBUTES
  10.    pLuid As LUID
  11.    Attributes As Long
  12. End Type
  13. Private Type TOKEN_PRIVILEGES
  14.    PrivilegeCount As Long
  15.    Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
  16. End Type
  17. Private Declare Function SetSystemPowerState Lib "kernel32" (ByVal fSuspend As Long, ByVal fForce As Long) As Long
  18. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
  19. Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
  20. Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
  21. Private Declare Function AdjustTokenPrivileges Lib "advapi32" (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
  22. 'set the shut down privilege for the current application
  23. Private Sub EnableShutDown()
  24.    Dim hProc As Long
  25.    Dim hToken As Long
  26.    Dim mLUID As LUID
  27.    Dim mPriv As TOKEN_PRIVILEGES
  28.    Dim mNewPriv As TOKEN_PRIVILEGES
  29.    hProc = GetCurrentProcess()
  30.    OpenProcessToken hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken
  31.    LookupPrivilegeValue "", "SeShutdownPrivilege", mLUID
  32.    mPriv.PrivilegeCount = 1
  33.    mPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
  34.    mPriv.Privileges(0).pLuid = mLUID
  35.    ' enable shutdown privilege for the current application
  36.    AdjustTokenPrivileges hToken, False, mPriv, 4 + (12 * mPriv.PrivilegeCount), mNewPriv, 4 + (12 * mNewPriv.PrivilegeCount)
  37. End Sub
  38. Private Sub Form_Load()
  39.    'KPD-Team 2001
  40.    'URL: http://www.allapi.net/
  41.    'E-Mail: KPDTeam@Allapi.net
  42.    'enable the shutdown privilege
  43.    EnableShutDown
  44.    'on Windows2000: hibernate
  45.    'on Windows9x/ME: suspend
  46.    SetSystemPowerState False, False
  47. End Sub
  48.  

para mas info consulta en la Api Guide:
GetPwrCapabilities
IsPwrHibernateAllowed
IsPwrShutdownAllowed
IsPwrSuspendAllowed
SetSuspendedState
SetSystemPowerState


Título: Re: Suspender pc desde VB
Publicado por: Littl3 en 27 Mayo 2008, 09:40 am
Gracias, haber si me empapo bien las apis porque parece que son esenciales y faciles de usar, salu2


Título: Re: Suspender pc desde VB
Publicado por: cobein en 27 Mayo 2008, 17:14 pm
From M$

SetSystemPowerState Function

[SetSystemPowerState is available for use in the operating systems listed in the Requirements section. It may be altered or unavailable in subsequent versions. Applications written for Windows Vista and later should use SetSuspendState instead.]