• vb6 的关机代码


    Public Const SE_PRIVILEGE_ENABLED As Integer = &H2
    Public Const TOKEN_QUERY As Integer = &H8
    Public Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20
    Public Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege"
    Public Const EWX_LOGOFF As Integer = &H0 '注销计算机
    Public Const EWX_SHUTDOWN As Integer = &H1 '关闭计算机
    Public Const EWX_REBOOT As Integer = &H2 '重新启动计算机
    Public Const EWX_FORCE As Integer = &H4 '关闭所有进程,注销计算机
    Public Const EWX_POWEROFF As Integer = &H8
    Public Const EWX_FORCEIFHUNG As Integer = &H10
    Public Const SPI_GETWORKAREA = &H30

    Private Type Luid
        dwLowPart As Long
        dwHighPart As Long
    End Type

    Private Type LUID_AND_ATTRIBUTES
        udtLUID As Luid
        dwAttributes As Long
    End Type

    Private Type TokPriv1Luid
        Count As Integer
        Luid As Luid
        Attr As Integer
    End Type

    Private Declare Function ExitWindowsEx Lib "user32" _
    (ByVal dwOptions As Long, _
    ByVal dwReserved As Long) As Long

    Private Declare Function GetCurrentProcess Lib "kernel32" () 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 TokPriv1Luid, _
    ByVal BufferLength As Long, _
    PreviousState As Any, _
    ReturnLength As Long) As Long

    Private Sub DoExitWin(ByVal flg As Integer)
        Dim xc As Boolean '判断语句
        Dim tp As TokPriv1Luid
        Dim hproc As Long
        hproc = GetCurrentProcess()
       
        '调用进程值
        Dim htok As Long
        htok = 0
       
        xc = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, htok)
        tp.Count = 1
        tp.Attr = SE_PRIVILEGE_ENABLED
       
        xc = LookupPrivilegeValue(vbNullString, SE_SHUTDOWN_NAME, tp.Luid)
        xc = AdjustTokenPrivileges(htok, False, tp, ByVal 0&, ByVal 0&, ByVal 0&)
        xc = ExitWindowsEx(flg, 0)
    End Sub

    Public Sub Reboot()
        Dim flg As Integer
        flg = EWX_FORCE Or EWX_REBOOT
        DoExitWin flg '重新启动计算机
    End Sub

    Public Sub PowerOff()
        Dim flg As Integer
        flg = EWX_FORCE Or EWX_POWEROFF
        DoExitWin flg '关闭计算机
    End Sub

    Public Sub Logout()
        Dim flg As Boolean
        flg = EWX_FORCE Or EWX_LOGOFF
        DoExitWin flg '注销计算机
    End Sub

  • 相关阅读:
    js处理富文本编辑器转义、去除转义、去除HTML标签
    web sec tools / Arachni
    OS + Linux IP / Inside IP / Outside IP
    OS + Linux SMB / Samba
    OS + Linux NTP Server
    my live / PC NAS / weiliantong QNAP TS-532X 4.5.1.1495 / cipanzhenlie / raid / Synology
    summarise() regrouping output 警告
    binary_crossentropy和BinaryCrossentropy的区别
    损失函数BinaryCrossentropy例子说明
    理解功能强大的sed替换命令
  • 原文地址:https://www.cnblogs.com/lbnnbs/p/4784609.html
Copyright © 2020-2023  润新知