ShutDownWindows – Shut down and reboot the operating system

ShutDownWindows – Shut down and reboot the operating system

Private Type LUID   LowPart As Long   HighPart As LongEnd TypePrivate Type TOKEN_PRIVILEGES    PrivilegeCount As Long    LuidUDT As LUID   Attributes As LongEnd TypeConst TOKEN_ADJUST_PRIVILEGES = &H20Const TOKEN_QUERY = &H8Const SE_PRIVILEGE_ENABLED = &H2Const EWX_SHUTDOWN = 1Const EWX_REBOOT = 2Const EWX_FORCE = 4Private Declare Function GetVersion Lib "kernel32" () As LongPrivate Declare Function GetCurrentProcess Lib "kernel32" () As LongPrivate Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle _    As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As LongPrivate Declare Function LookupPrivilegeValue Lib "advapi32" Alias _    "LookupPrivilegeValueA" (ByVal lpSystemName As String, _    ByVal lpName As String, lpLuid As LUID) As LongPrivate Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal _    TokenHandle As Long, ByVal DisableAllPrivileges As Long, _    NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, _    PreviousState As Any, ReturnLength As Any) As LongPrivate Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Long, _    ByVal dwReserved As Long) As Long' Shut down windows, and optional reboot it' if the 2nd argument is True, no WM_QUERYENDSESSION and WM_ENDSESSION' messages are sent to active applicationsSub ShutDownWindows(ByVal Reboot As Boolean, Optional ByVal Force As Boolean)    Dim hToken As Long    Dim tp As TOKEN_PRIVILEGES    Dim flags As Long        ' Windows NT/2000 require a special treatment    ' to ensure that the calling process has the    ' privileges to shut down the system        ' under NT the high-order bit (that is, the sign bit)    ' of the value retured by GetVersion is cleared    If GetVersion() >= 0 Then        ' Open this process for adjusting its privileges        OpenProcessToken GetCurrentProcess(), (TOKEN_ADJUST_PRIVILEGES Or _            TOKEN_QUERY), hToken                ' Get the LUID for shutdown privilege.        ' retrieves the locally unique identifier (LUID) used        ' to locally represent the specified privilege name        ' (first argument = "" means the local system)        LookupPrivilegeValue "", "SeShutdownPrivilege", tp.LuidUDT                ' complete the TOKEN_PRIVILEGES structure with the # of        ' privileges and the desired attribute        tp.PrivilegeCount = 1        tp.Attributes = SE_PRIVILEGE_ENABLED                ' enables or disables privileges in the specified access token        ' last 3 arguments are zero because we aren't interested        ' in previous privilege attributes.        AdjustTokenPrivileges hToken, False, tp, 0, ByVal 0&, ByVal 0&    End If        ' prepare shutdown flags    flags = EWX_SHUTDOWN    If Reboot Then flags = flags Or EWX_REBOOT    If Force Then flags = flags Or EWX_FORCE        ' finally, you can shut down Windows    ExitWindowsEx flags, &HFFFF    End Sub

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes