Search code examples
windowspowershellsysinternals

Autologon.exe via command line and get result


Is there a way I can execute sysinternals Autologon.exe from command line (Powershell) and get the result, i.e. know if the credentials entered were correct?

If I use the GUI and not the command line then I do get message with this info..

Thanks.


Solution

  • You can run any Windows .exe/cmd/bat/vbs from PoSH, as long as you call it correctly.

    PowerShell: Running Executables https://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx

    There are several different methods for running executables as well as invoking code. How do you know which one to use for the job? Here is an outline of the methods with examples and general use.

    Regarding --- "If I use the GUI and not the command line then I do get message with this info.."

    This is because Autologon.exe is doing this work and returning the result. SO, it's Autologon. PoSH will not get in Autologon's way / process, but you can get the exit code from external tools as long as you know what they are. I've not tried to this with Autologon. Yet, in most cases, it's a Boolean response: success or failure, 0 or 1, or 1 or 2. The Start-Process cmdlet allows you to trap error / exit code from a process, using the -PassThru parameter. Often that is use in concert with the -wait parameter as well.

    Something like:

    $AutologExitCode = Start-Process -FilePath = Autologon.exe -ArgumentList $SomeArguments -NoNewWindow -Wait -PassThru
    "The error/exit code from AutoLogon is  $($AutologonExitCode.ExitCode)"
    

    Full disclosure: We do not allow Autologon in our environment. So, I've spent no time using Autologon, but the above premise would be the same as other exe's.