Invoking the Windows Security Dialog (in C# or VB.NET)

前端 未结 5 1210
你的背包
你的背包 2021-02-06 04:31

I would like to know how to invoke the Windows Security Dialog (press ctrl+alt+del on a windows workstation NOTE: I don\'t want the task manager!) programmatically.

相关标签:
5条回答
  • 2021-02-06 04:58

    You might want to take a look at the SendInput hook in User32: http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx and http://pinvoke.net/default.aspx/user32/SendInput.html

    0 讨论(0)
  • 2021-02-06 05:01

    I would imagine something like this, get the handle of the desktop, using 'GetDesktopWindow', make sure the focus is set to the handle, and Send a keystroke 'Ctrl+Alt+Del' using 'SendInput' or use the 'SendMessage' to send the keystrokes to that handle returned by GetDesktopWindow. It is not guaranteed to work as that is top-off-my-head.

    Hope this helps, Best regards, Tom.

    0 讨论(0)
  • 2021-02-06 05:03

    You can try call WlxLoggedOnSAS function from GINA or WlxSasNotify from WinLogon. But, I afraid it won't work. But, maybe it will lead you to working method. And it definitely will not work in Vista/W7.

    In other side, it might be that Windows Security Dialog can be called only by secure attention sequence ( ctrl+alt+del) by securytt reasons.

    0 讨论(0)
  • 2021-02-06 05:13

    Security features might be standing in your way to programmatically manage security-related features like Security Dialog through CtrlAltDel. I've been running into the same kinds of problems.

    About your request to invoke password change dialog.

    IADsUser

    "designed to represent and manage an end-user account on a network [and locally]."

    If you find yourself short on solutions, you might whip up your own quick Windows form with password fields and communicate with the Windows IADsUser Interface using the WinNT provider to bind to a local (instead of network) user account on the XP machine.

    GetObject("WinNT://MYCOMPUTER/jeffsmith,user") //WinNT provider
    

    ... and use the ChangePassword(..) method (links to code sample).

    usr.ChangePassword szOldPass, szNewPass
    

    If you're trying to invoke the Windows features directly to cause the user to trust the process then admittedly a custom form for changing a password might look a bit goofy.

    RunDLL32

    Another avenue you might try is programmatically invoking RunDLL32.exe at the command line and targeting the correct Win DLL to bring up the password change dialog box. One forum said the following works in XP if SP2 isn't installed. I can't test it because I'm on Vista.

    rundll32.exe shell32.dll,Control_RunDLL password.cpl
    

    You can Google for many of these, however it does seem to come up short as far as changing the password or invoking Windows security dialog.

    Microsoft's info about Run32Dll

    0 讨论(0)
  • 2021-02-06 05:23

    This is a workaround i found on other forum. It works for me.

    Private Function IsRunAsAdministrator() As Boolean
    
        Dim wi = WindowsIdentity.GetCurrent()
        Dim wp = New WindowsPrincipal(wi)
    
        Return wp.IsInRole(WindowsBuiltInRole.Administrator)
    
    End Function
    

    'i use it on formload, you can have it whenever needed

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        If Not IsRunAsAdministrator() Then
            Dim processInfo = New ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase)
            processInfo.UseShellExecute = True
            processInfo.Verb = "runas"
            Try
    
                Process.Start(processInfo)
    
            Catch ew1 As Exception
                MessageBox.Show("Sorry, this application must be run as Administrator.")
            End Try
            'Application.Current.Shutdown()
            Application.ExitThread()
        Else
       'your statement here
      End If
    End Sub
    
    0 讨论(0)
提交回复
热议问题