禁止命令行但显示凭据

时间:2017-05-26 07:58:32

标签: powershell command-line exe credentials

我想禁止命令行的登录。并且只想查看凭证窗口。 到目前为止,脚本正在使用此命令

   Add-Type -Name win -MemberDefinition '[DllImport("user32.dll")] public 
   static extern bool ShowWindow(int handle, int state);' -Namespace native
   [native.win]::ShowWindow(([System.Diagnostics.Process]:: 
   GetCurrentProcess() | Get-Process).MainWindowHandle,0)

我已经将脚本编译为exe,但它的工作原理到目前为止除了禁止使用凭证窗口而不是命令行登录。

我尝试了各种解决问题的解决方案,但没有任何效果。

2 个答案:

答案 0 :(得分:0)

Start-Process "powershell.exe" -ArgumentList '-Command "
$Cred = Get-Credential
Add-Type -AssemblyName "System.Windows.Forms"
[System.Windows.Forms.MessageBox]::Show($Cred.Username)
"' -WindowStyle Hidden

你正在隐藏进程窗口句柄低级别 - 因为凭据窗口是它的子级,它也会导致它消失,但是启动带有隐藏窗口的PowerShell不会抑制其他/子窗口。

以上代码将在消息框弹出窗口中输出用户名,而不显示PS窗口。

答案 1 :(得分:0)

没关系,谢谢你的帮助!我找到了解决问题的另一种方法。当我将.ps1编译为.exe时,我可以设置参数-console,这是有效的。