elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Arreglado, de nuevo, el registro del warzone (wargame) de EHN


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Suspender pc desde VB
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Suspender pc desde VB  (Leído 3,336 veces)
Littl3

Desconectado Desconectado

Mensajes: 239


Tarde o temprano aparece el hombre


Ver Perfil
Suspender pc desde VB
« 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?


En línea

seba123neo
Moderador
***
Desconectado Desconectado

Mensajes: 3.621



Ver Perfil WWW
Re: Suspender pc desde VB
« Respuesta #1 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.


En línea

SERBice


Desconectado Desconectado

Mensajes: 934


Ver Perfil WWW
Re: Suspender pc desde VB
« Respuesta #2 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
En línea

Littl3

Desconectado Desconectado

Mensajes: 239


Tarde o temprano aparece el hombre


Ver Perfil
Re: Suspender pc desde VB
« Respuesta #3 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
En línea

cobein


Desconectado Desconectado

Mensajes: 759



Ver Perfil WWW
Re: Suspender pc desde VB
« Respuesta #4 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.]
En línea

http://www.advancevb.com.ar
Más Argentino que el morcipan
Aguante el Uvita tinto, Tigre, Ford y seba123neo
Karcrack es un capo.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Suspender el PC
Dudas Generales
skan 0 2,674 Último mensaje 20 Julio 2011, 01:01 am
por skan
No suspender notebook
Windows
Xedrox 1 1,834 Último mensaje 2 Mayo 2013, 07:52 am
por Trane!
icono suspender
Dudas Generales
okik 2 3,016 Último mensaje 31 Agosto 2016, 16:02 pm
por Eleкtro
suspender pc
Windows
DaVinci4 4 2,964 Último mensaje 5 Abril 2023, 18:00 pm
por Danielㅤ
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines