Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, April 26, 2017 5:18 AM
In ubuntu, terminal will prompt user to confirm the close of a window where command still running, so that user will not terminate their command by mistake.
Does powershell have similar setting? How to enable it?
And although powershell does not accept the alt+F4 shortcut, powershell ISE does, still with no user prompt. And the whole powershell ISE can even exit entirely by simply typing 'exit' in one powershell tab within the ISE. Is there a way to prevent this?
All replies (5)
Wednesday, April 26, 2017 6:40 AM
Hi,
- One-time Fix: Run your script from the PowerShell Console, or launch the PowerShell process using the -NoExit switch. e.g.
PowerShell -NoExit "C:\SomeFolder\SomeScript.ps1"
- Per-script Fix: Add a prompt for input to the end of your script file. e.g.
Read-Host -Prompt "Press Enter to exit"
- Global Fix: Change your registry key to always leave the PowerShell Console window open after the script finishes running.
Please refer the below link for further details:
http://blog.danskingdom.com/keep-powershell-console-window-open-after-script-finishes-running/
regards,
Shenuka Fernando
Wednesday, April 26, 2017 6:32 PM | 1 vote
You are answering a question I did not ask.
My question is "Powershell close without prompting user when command still running", but what you answered is "Powershell close when script finish running".
To be more clear, I will give you an example: I open a powershell window, do some stuff like running a python script, the script is not finish running, but user can still close that powershell window without any warning that there is a program still running, thus, a script might be terminated by mistake, like click on the "X" but actually want to minimize the window.
Thursday, April 27, 2017 11:33 AM
Hi,
Try to add the below cmdlets.
$caption = "Please Confirm"
$message = "Are you Sure You Want To Proceed:"
[int]$defaultChoice = 0
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Do the job."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Do not do the job."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$choiceRTN = $host.ui.PromptForChoice($caption,$message, $options,$defaultChoice)
if ( $choiceRTN -ne 1 )
{
"Your Choice was Yes"
}
else
{
"Your Choice was NO"
}
Thursday, April 27, 2017 4:54 PM | 1 vote
You see, I want to prevent the close of powershell window when there is something still running, that is to say, pop a window or something to confirm close when click 'X' with something still running.
What if I'm running a .bat script? or a python script? or some console based program? or just using get-content -tail?
Please do not post another useless answer. Thank you.
Tuesday, May 2, 2017 9:45 AM
Hi Misairu.GuGu,
As far as I know, there is no such setting. I have not found any way to implement this. But, you could ask our PowerShell forum for further assistance. They may have other suggestions or workarounds for you.
https://social.technet.microsoft.com/Forums/windows/en-US/home?forum=winserverpowershell
Best regards
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].