从vb.net

时间:2016-02-24 14:56:05

标签: wpf vb.net windows-identity

我正在尝试从另一个拥有管理员权限的帐户运行一个exe,我到目前为止已经有了这个,但它给了我一个未知的错误(0xfffffffe):

Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Int32) As Boolean
End Function
Public Sub RunAsAdmin()
    Dim tokenHandle As New IntPtr(0)
    If LogonUser(_ImpersinateUser, _ImpersinateDomain, _ImpersinatePassword, 2, 0, tokenHandle) Then

        Dim newId As New WindowsIdentity(tokenHandle)
        Using impersonatedUser As WindowsImpersonationContext = newId.Impersonate()


            Dim p As New Process
            p.StartInfo.FileName = "C:\\Temp\\MCPR.exe"
            p.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            p.Start()
            ShowWindow(p.MainWindowHandle, SW_RESTORE)

        End Using
    End If
End Sub

0 个答案:

没有答案