PDA

View Full Version : سؤال (خاموش موقت)



jafar_ho
شنبه 30 دی 1385, 07:46 صبح
با سلام
دوستان خسته نباشید .
یک سؤال ...
چطور می شود در vb سیستم را standby کرد ؟؟؟؟؟؟
با تشکر . منتظر جواب هستم .

S_VB.max
شنبه 30 دی 1385, 13:35 عصر
http://www.shaygan.com/show.php?idsub=201

jafar_ho
شنبه 30 دی 1385, 18:18 عصر
دست شما درد نکند .
ولی این که standby نداشت !!!!!!!!

S_VB.max
یک شنبه 01 بهمن 1385, 18:51 عصر
Private Declare Function GetLastError Lib "KERNEL32" () As Long

Private Type LUID
UsedPart As Long
IgnoredForNowHigh32BitPart As Long
End Type

Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type

Private Declare Function GetCurrentProcess Lib "KERNEL32" () As Long
Private Declare Sub SetLastError Lib "KERNEL32" (ByVal dwErrCode As Long)
Private Declare Function SetSystemPowerState Lib "KERNEL32" (ByVal fSuspend As Long, ByVal fForce As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
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

Public Sub StandBy(Mode As Boolean, Optional Force As Integer = 1)
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2

Dim hdlProcessHandle As Long
Dim hdlTokenHandle As Long
Dim tmpLuid As LUID
Dim tkp As TOKEN_PRIVILEGES
Dim tkpNewButIgnored As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long

SetLastError 0
hdlProcessHandle = GetCurrentProcess()

If GetLastError <> 0 Then
MsgBox "GetCurrentProcess error==" & GetLastError
End If

OpenProcessToken hdlProcessHandle, _
(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle

If GetLastError <> 0 Then
MsgBox "OpenProcessToken error==" & GetLastError
End If

LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid

If GetLastError <> 0 Then
MsgBox "LookupPrivilegeValue error==" & GetLastError
End If

tkp.PrivilegeCount = 1
tkp.TheLuid = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED

AdjustTokenPrivileges hdlTokenHandle, False, tkp, _
Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded

If GetLastError <> 0 Then
MsgBox "AdjustTokenPrivileges error==" & GetLastError
End If

SetSystemPowerState Mode, Force
End Sub

sohrab o
دوشنبه 02 بهمن 1385, 00:16 صبح
آقا مطلب بسیار جالب بود