Перекидываю тебе код, который кинул мне sne. Он в моей теме пропал, так что лови тут:
AdjustTolkienPriv. - получение необходимых прав программой...В этом случае нужно поэкспериментировать с флагами...
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () 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, B
yVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function SetSystemPowerState Lib "kernel32" (ByVal fSuspend As Long, ByVal fForce As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const ANYSIZE_ARRAY = 1
Private Const ERROR_SUCCESS = 0&
Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const EWX_LOGOFF = &H0& ' завершение сеанса пользователя
Private Const EWX_SHUTDOWN = &H1& ' шатдаун компьютера
Private Const EWX_REBOOT = &H2& ' перез
агрузка компьютера
Private Const EWX_POWEROFF = &H8& ' выключение компьютера (ATX)
Private Const EWX_FORCE = &H4& ' флаг принудительного выполнения операции
Private Const EWX_FORCEIFHUNG = &H10& ' флаг принудительного выполнения при зависании
Private Type LUID
UsedPart As Long: IgnoredForNowHigh32BitPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
TheLuid As LUID: Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long: TheLuid As LUID: Attributes As Long
End Type
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long: dwMajorVersion As Long: dwMinorVersion As Long
dwBuildNumber As Long: dwPlatformId As Long: szCSDVersion As String * 128
End Type
Public Function OsVersion(Back As Integer) As String
Dim info As OSVERSIONINFO
info.dwOSVersionInfoSize = Len(info)
Ge
tVersionEx info
If Back = 0 Then OsVersion = CInt(info.dwPlatformId)
If Back = 1 Then
Select Case info.dwPlatformId
Case 0
OsVersion = ""
Case 1
OsVersion = "Windows 9x" & " v" & info.dwMajorVersion & "."
OsVersion = OsVersion & info.dwMinorVersion & " Build "
OsVersion = OsVersion & info.dwBuildNumber
Case 2
OsVersion = "Windows NT" & " v" & info.dwMajorVersion & "."
OsVersion = OsVersion & info.dwMinorVersion & " Build "
OsVersion = OsVersion & info.dwBuildNumber
End Select
End If
If Back = 3 Then OsVersion = info.dwMajorVersion
Back = 0
End Function
Public Function Shutdown() As Boolean
Select Case OsVersion(False)
Case Is = VER_PLATFORM_WIN32s
Shutdown = False
Case Is = VER_PLATFORM
_WIN32_WINDOWS
ExitWindowsEx EWX_SHUTDOWN, 0&
Shutdown = True
Case Is = VER_PLATFORM_WIN32_NT
AdjustToken
ExitWindowsEx EWX_SHUTDOWN Or EWX_POWEROFF, 0
Shutdown = True
End Select
End Function
Public Function Restart() As Boolean
Select Case OsVersion(False)
Case Is = VER_PLATFORM_WIN32s
Restart = False
Case Is = VER_PLATFORM_WIN32_WINDOWS
ExitWindowsEx EWX_REBOOT, 0&
Restart = True
Case Is = VER_PLATFORM_WIN32_NT
AdjustToken
ExitWindowsEx EWX_REBOOT, 0
Restart = True
End Select
End Function
Public Sub LogOff()
ExitWindowsEx EWX_LOGOFF, 0&
End Sub
Public Sub Suspend()
If OsVersion(False) = VER_PLATFORM_WIN32_NT Then AdjustToken
SetSystemPowerState True, False
End Sub
Pub
lic Sub Hibernate()
If OsVersion(False) = VER_PLATFORM_WIN32_NT Then AdjustToken
SetSystemPowerState False, False
End Sub
Private Function AdjustToken() As Long
Const TOKEN_ADJUST_PRIVILEGES = &H20: Const TOKEN_QUERY = &H8
Dim hdlProcessHandle As Long, hdlTokenHandle As Long, lBufferNeeded As Long
Dim tmpLuid As LUID: Dim tkp As TOKEN_PRIVILEGES
Dim tkpNewButIgnored As TOKEN_PRIVILEGES
hdlProcessHandle = GetCurrentProcess()
OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkp.PrivilegeCount = 1
tkp.TheLuid = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED
AdjustTokenPrivileges hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded
End Function
*********************************************************** *
Ответить на это сообщение
Посетить форум
************************************************************
После этого используешь этот поистине гениальный процедура, который я написал всего за два неделя: