none
Invoking runas.exe from System.Diagnostics.Process RRS feed

  • Question

  • I have a scenario where I need to allow my users to connect SSMS but using a different domain account than the one they are currently logged in as.
    From command prompt it is simply:

    RUNAS /user:SOMEDOMAIN\SomeUserName /netonly "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"


    it will then prompt me with a message saying: "Enter the password for SOMEDOMAIN\SomeUserName"
    upon supplying the password it will launch SSMS with the associated domain credentials

    I sought to wrap this functionality in a simply forms application that would capture the user's username/password and pass them to runas to launch the app.
    So after reading up on the System.Diagnostics.ProcessStartInfo propeties for RedirectStandardOutput, RedirectStandardError and RedirectStandardInput I thought I had a solution. But for some reason I cannot figure out when I set it to redirect the input/output the runas command doesn't 'wait' for my input to the password prompt, it simply launches the exe and I can't trap it or make it wait for me to write to the StandardInput StreamWriter to supply the password.

    How do I get this to work?



    Friday, October 26, 2012 2:56 PM

Answers

  • The password prompt is not from the target process, it is from Windows. If you pass the runas verb to Windows Shell on a modern version of Windows you will get a UAC consent dialog and you cannot override it.

    you can p-invoke CreateProcessWithLogonW  or CreateProcessAsUser to launch SSMS.



    Visual C++ MVP

    Friday, October 26, 2012 6:33 PM