当前位置:编程学习 > C#/ASP.NET >>

安装部署问题 如何实现在安装完成后重启PC

安装部署问题

制作安装程序,如何实现在安装完成后重启PC?

谢谢! --------------------编程问答-------------------- 哪位大侠可以回答我 --------------------编程问答-------------------- 下面的代码是关于,关机,重启等的。你可以参考一下。http://www.bingning.net

<System.Runtime.InteropServices.DllImport("kernel32.dll")> _
Private Shared Function GetCurrentProcess() As IntPtr
End Function

<System.Runtime.InteropServices.DllImport("advapi32.dll", SetLastError:=True)> _
Shared Function OpenProcessToken(ByVal ProcessHandle As IntPtr, _
    ByVal DesiredAccess As Integer, _
    ByRef TokenHandle As IntPtr) As Boolean
End Function

<System.Runtime.InteropServices.DllImport("advapi32.dll", SetLastError:=True, _
    CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
Shared Function LookupPrivilegeValue(ByVal lpSystemName As String, _
    ByVal lpName As String, _
    ByRef lpLuid As Long) As Boolean
End Function

<System.Runtime.InteropServices.StructLayout( _
    System.Runtime.InteropServices.LayoutKind.Sequential, Pack:=1)> _
Private Structure TOKEN_PRIVILEGES
    Public PrivilegeCount As Integer
    Public Luid As Long
    Public Attributes As Integer
End Structure

<System.Runtime.InteropServices.DllImport("advapi32.dll", SetLastError:=True)> _
Private Shared Function AdjustTokenPrivileges(ByVal TokenHandle As IntPtr, _
    ByVal DisableAllPrivileges As Boolean, _
    ByRef NewState As TOKEN_PRIVILEGES, _
    ByVal BufferLength As Integer, _
    ByVal PreviousState As IntPtr, _
    ByVal ReturnLength As IntPtr) As Boolean
End Function

Public Sub AdjustToken()
    Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20
    Const TOKEN_QUERY As Integer = &H8
    Const SE_PRIVILEGE_ENABLED As Integer = &H2
    Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege"

    If Environment.OSVersion.Platform <> PlatformID.Win32NT Then
        Return
    End If

    Dim procHandle As IntPtr = GetCurrentProcess()

    Dim tokenHandle As IntPtr
    OpenProcessToken(procHandle, _
        TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, tokenHandle)
    Dim tp As New TOKEN_PRIVILEGES()
    tp.Attributes = SE_PRIVILEGE_ENABLED
    tp.PrivilegeCount = 1
    LookupPrivilegeValue(Nothing, SE_SHUTDOWN_NAME, tp.Luid)
    AdjustTokenPrivileges(tokenHandle, False, tp, 0, IntPtr.Zero, IntPtr.Zero)
End Sub

补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,