Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: Как отключить комп в XP Добавлено: 30.01.04 21:09  

Автор вопроса:  wishco

Нужен код как выключить комп в XP те. что-бы не было таблички теперь вы можете выключить питание вашего компьютера. Только выход из Windows Это не то, тут что-то другое.

Ответить

  Ответы Всего ответов: 2  

Номер ответа: 1
Автор ответа:
 Grayich



ICQ: 208280504 

Вопросов: 56
Ответов: 164
 Web-сайт: grayich.narod.ru
 Профиль | | #1
Добавлено: 30.01.04 22:51

Уважаемый наберите а поиске :))  выключение компьютера :)))

Ответить

Номер ответа: 2
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #2
Добавлено: 31.01.04 00:26

Option Explicit     ' О сколько нам открытий чудных, готовит юзера Винда!

 

Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved 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 GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) 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
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function SetSystemPowerState Lib "kernel32.dll" (ByVal fSuspend As Long, ByVal fForce As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

 

Private Type OSVERSIONINFO ' Версия виндовоськи
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
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 Const EWX_SHUTDOWN As Long = &H1&
Private Const EWX_REBOOT As Long = &H2&
Private Const EWX_FORCE As Long = &H4&
Private Const EWX_POWEROFF As Long = &H8&

 

Private iMonEvent As Long

 

Private Sub AdjustToken(sPrivilege As String) 'Получение нужных нам привелегий
Dim hdlTokenHandle As Long, lBufferNeeded As Long
Dim tkp As TOKEN_PRIVILEGES, tkpNewButIgnored As TOKEN_PRIVILEGES

 

Call OpenProcessToken(ByVal GetCurrentProcess(), (&H20 Or &H8), hdlTokenHandle)
Call LookupPrivilegeValue(vbNullString, sPrivilege, tkp.TheLuid)

 

tkp.PrivilegeCount = &H1
tkp.Attributes = &H2

 

Call AdjustTokenPrivileges(hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded)
End Sub

 

Public Sub ShutdownSystem()
If OS_Version.dwPlatformId = &H2 Then Call AdjustToken("SeShutdownPrivilege")
Call ExitWindowsEx(EWX_SHUTDOWN Or EWX_POWEROFF Or EWX_FORCE, 0&)
End Sub

 

Public Sub RestartSystem()
If OS_Version.dwPlatformId = &H2 Then Call AdjustToken("SeShutdownPrivilege")
Call ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0&)
End Sub

 

Public Sub LogOff()
Call ExitWindowsEx(&H0, &H0)
End Sub

 

Public Sub Suspend(bHibirnate As Boolean)
If OS_Version.dwPlatformId = &H2 Then Call AdjustToken("SeShutdownPrivilege")
Call SetSystemPowerState(IIf(bHibirnate, False, True), True)
End Sub

 

Public Sub StartScrSaver()
Call SendMessage(frmMain.hWnd, &H112, &HF140&, 0)
End Sub

 

Public Sub MonPower(Optional iEvent As Integer = &HFFFF)
If iMonEvent = &H2 Or iMonEvent = &H1 Then
iMonEvent = &HFFFF
ElseIf iMonEvent = &H0 Or iMonEvent = &HFFFF Then
iMonEvent = iEvent
End If

 

Call SendMessage(frmMain.hWnd, &H112&, &HF170&, iMonEvent)
End Sub

 

Private Function OS_Version() As OSVERSIONINFO ' dwPlatformId 0-Unknown; 1-9x; 2-NT
OS_Version.dwOSVersionInfoSize = Len(OS_Version)
Call GetVersionEx(OS_Version)
End Function


Все что нужно это - AdjustTokenPrivileges

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам