再起動方法
- 題名: 再起動方法
- 著者: まつまつ
- 日時: 2005/11/15 18:18:42
- ID: 13712
- この記事の返信元:
- この記事への返信:
- ツリーを表示
- 題名: Re[1]: 再起動方法
- 著者: 渋木宏明(ひどり)
- URL: http://hidori.jp/
- 日時: 2005/11/15 19:35:35
- ID: 13716
- この記事の返信元:
-
[13712] 再起動方法 まつまつ 2005/11/15 18:18:42
- この記事への返信:
- ツリーを表示
- 題名: Re[3]: 再起動方法
- 著者: まつまつ
- 日時: 2005/11/16 9:47:19
- ID: 13730
- この記事の返信元:
- この記事への返信:
- ツリーを表示
分類:[.NET]
再起動が出来ません。どなたか助けて下さい。
以下のようなソースですが、間違いをご指摘頂けないでしょうか?
Public Structure LUID_AND_ATTRIBUTES
Dim Luid As LUID
Dim Attributes As Integer
End Structure
Public Structure TOKEN_PRIVILEGES
Dim PrivilegeCount As Integer
Dim Privileges As LUID_AND_ATTRIBUTES
End Structure
Public Structure LUID
Dim LowPart As Integer
Dim HighPart As Integer
End Structure
Public Declare Function GetCurrentProcess Lib "kernel32" () As IntPtr
Public Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As IntPtr, ByVal DesiredAccess As Integer, ByRef TokenHandle As IntPtr) As Integer
Public Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, ByRef LpLuid As LUID) As Integer
Public Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (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 Integer
Public Const TOKEN_QUERY As Integer = &H8
Public Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20
Public Const SE_SHUTDOWN_NAME As String = "RestartWindows"
Public Const SE_PRIVILEGE_ENABLED As Integer = &H2
と宣言しておいて、
Private Shared Sub SetRestartPrivilege()
Dim luid_no As LUID
Dim tp As New TOKEN_PRIVILEGES
Dim hProc As IntPtr
Dim hToken As IntPtr
Dim sts As Integer
Dim ecode As Integer
hProc = Process.GetCurrentProcess().Handle
sts = OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken)
sts = LookupPrivilegeValue(vbNullString, SE_SHUTDOWN_NAME, luid_no)
tp.PrivilegeCount = 1
tp.Privileges = New LUID_AND_ATTRIBUTES
tp.Privileges.Luid = luid_no
tp.Privileges.Attributes = SE_PRIVILEGE_ENABLED
sts = AdjustTokenPrivileges(hToken, False, tp, 0, IntPtr.Zero, IntPtr.Zero)
End Sub
で再起動したいのですが...