zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    ButterKnife的使用以及不能自动生成代码问题的解决
    Android事件传递机制
    Java中四种引用类型
    Swiper
    table合并单元格 colspan(跨列)和rowspan(跨行)
    常用JS图片滚动(无缝、平滑、上下左右滚动)代码大全
    解决firefox、chrome不兼容cursor:hand 设置鼠标为手型的方法
    js 验证表单 js提交验证类
    怎么解决浏览器兼容性问题
    JavaScript作用域链
  • 原文地址:https://www.cnblogs.com/lbnnbs/p/4784609.html
Copyright © 2011-2022 走看看