打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VB.Net远程控制编程实例[注销关机重启]
VB.Net远程控制编程实例[注销关机重启]
作者:IVA    来源:乐博网转化     更新时间:2007-12-16

原代码为C#编写,由L3'Studio团队开发;乐博网将其转化为VB.Net代码

功能描述:管理类(主要有关机重启等功能,API函数实现)

相关事件 :注销 关机 重启

命名空间:Lob.Windows

子类:WindowsManager

转化后代码如下:
    
Imports System
Imports System.Runtime.InteropServices
Namespace Lob.Windows

    Public Class WindowsManager

        Friend Const SE_PRIVILEGE_ENABLED As Integer = 2

        Friend Const TOKEN_QUERY As Integer = 8

        Friend Const TOKEN_ADJUST_PRIVILEGES As Integer = 32

        Friend Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege"

        Friend Const EWX_LOGOFF As Integer = 0

        Friend Const EWX_SHUTDOWN As Integer = 1

        Friend Const EWX_REBOOT As Integer = 2

        Friend Const EWX_FORCE As Integer = 4

        Friend Const EWX_POWEROFF As Integer = 8

        Friend Const EWX_FORCEIFHUNG As Integer = 16

        Friend Declare Function GetCurrentProcess Lib "kernel32.dll" () As IntPtr

        Friend Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal h As IntPtr, ByVal acc As Integer, ByRef phtok As IntPtr) As Boolean

        Friend Declare Function LookupPrivilegeValue Lib "advapi32.dll" (ByVal host As String, ByVal name As String, ByRef pluid As Long) As Boolean

        Friend Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal htok As IntPtr, ByVal disall As Boolean, ByRef newst As TokPriv1Luid, ByVal len As Integer, ByVal prev As IntPtr, ByVal relen As IntPtr) As Boolean

        Friend Declare Function ExitWindowsEx Lib "user32.dll" (ByVal flg As Integer, ByVal rea As Integer) As Boolean

        Private Shared Sub DoExitWin(ByVal flg As Integer)
            Dim ok As Boolean
            Dim tp As TokPriv1Luid
            Dim hproc As IntPtr = GetCurrentProcess
            Dim htok As IntPtr = IntPtr.Zero
            ok = OpenProcessToken(hproc, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), htok)
            tp.Count = 1
            tp.Luid = 0
            tp.Attr = SE_PRIVILEGE_ENABLED
            ok = LookupPrivilegeValue(Nothing, SE_SHUTDOWN_NAME, tp.Luid)
            ok = AdjustTokenPrivileges(htok, False, tp, 0, IntPtr.Zero, IntPtr.Zero)
            ok = ExitWindowsEx(flg, 0)
        End Sub

        Public Shared Sub ShutDown()
            DoExitWin(EWX_SHUTDOWN)
        End Sub

        Public Shared Sub Reboot()
            DoExitWin(EWX_REBOOT)
        End Sub

        <StructLayout(LayoutKind.Sequential, Pack:=1)> _
        Structure TokPriv1Luid

            Public Count As Integer

            Public Luid As Long

            Public Attr As Integer
        End Structure
    End Class
End Namespace

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C#实现重启、关机、开关显示器的方法
实现关机-危险勿试
VB中如何实现系统的关机、重启和注销
windows mobile 下如何编程实现重启、关机(vb.net)(页 1) - 移动...
用VB制作简单的木马程序 -
VB实用代码,收藏!!
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服