VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

'This following code demostrate how to shutdown, reboot, lock workstation NT and hibernate system i

Ajander Singh  (1 Submission)   Windows API Call/Explanation   VB 6.0   Unknown Difficulty   Thu 22nd January 2004   Mon 8th February 2021

'This following code demostrate how to shutdown, reboot, lock workstation NT and hibernate system if supported

API Declarations


Option Explicit

'System Contants
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const TokenPrivileges = 3
Private Const ANYSIZE_ARRAY = 1
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"

'Shutdown constants
Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4
'Platform constants
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32s = 0

'OS version data structure
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Dim typOS As OSVERSIONINFO

Private Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type

Private Type LUID
lowpart As Long
highpart As Long
End Type

Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type

Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
'Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type

Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function SetSuspendState Lib "Powrprof.dll" (ByVal Hibernate As Integer, ByVal ForceCritical As Integer, ByVal DisableWakeEvent As Integer) As Integer
Private Declare Function IsPwrHibernateAllowed Lib "Powrprof.dll" () As Integer
Private Declare Function LockWorkStation Lib "user32" () 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 AdjustTokenPrivileges Lib "advapi32.dll" (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 LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long


Rate 'This following code demostrate how to shutdown, reboot, lock workstation NT and hibernate system i (1(1 Vote))
'This following code demostrate how to shutdown, reboot, lock workstation NT and hibernate system i.bas

'This following code demostrate how to shutdown, reboot, lock workstation NT and hibernate system i Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters