Autologon.exe 通过命令行获取结果

Autologon.exe via command line and get result

有什么方法可以从命令行 (Powershell) 执行 sysinternals Autologon.exe 并获得结果,即知道输入的凭据是否正确?

如果我使用 GUI 而不是命令行,那么我会收到包含此信息的消息..

谢谢。

您可以 运行 来自 PoSH 的任何 Windows .exe/cmd/bat/vbs,只要您正确调用它即可。

PowerShell:运行 可执行文件 https://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx

运行宁可执行文件和调用代码有几种不同的方法。您如何知道该使用哪一个?以下是带有示例和一般用途的方法概述。

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

这是因为 Autologon.exe 正在做这项工作并返回结果。所以,这是自动登录。 PoSH 不会妨碍 Autologon 的方式/过程,但您可以从外部工具获取退出代码,只要您知道它们是什么。我没有尝试过使用 Autologon。然而,在大多数情况下,它是一个布尔响应:成功或失败,0 或 1,或 1 或 2。Start-Process cmdlet 允许您使用 -PassThru 参数捕获进程中的错误/退出代码。这通常也与 -wait 参数一起使用。

类似于:

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

完全披露:我们不允许在我们的环境中自动登录。所以,我没有花时间使用 Autologon,但上述前提与其他 exe 相同。