项目作者: jsakamoto

项目描述 :
Ctrl+C Enabler for PowerShell
高级语言: C#
项目地址: git://github.com/jsakamoto/CtrlCEnabler.git
创建时间: 2018-01-26T14:05:04Z
项目社区:https://github.com/jsakamoto/CtrlCEnabler

开源协议:The Unlicense

下载


Ctrl+C Enabler for PowerShell

Summary

This is a .NET class library that allows you to enable Ctrl+C break on PowerShell console, always.

Why should be use this?

In some case, a PowerShell console, which is launched from Visual Studio IDE external tools menu, doesn’t accept Ctrl+C.

This class library can fix it :)

How to install in your PowerShell?

  1. Download “CtrlCEnabler.dll” from release page, and save it into “%HOME%\Documents\WindowsPowerShell” folder.
  2. Open the PowerShell console and enter the following command:
    1. PS> notepad $PROFILE
  3. Then, the file “Microsoft.PowerShell_profile.ps1” is opened in a text editor.
  4. Append lines as follows at the bottom of “Microsoft.PowerShell_profile.ps1”, and save it.
    1. # Enable Ctrl+C force.
    2. Add-Type -Path "$env:HOME\Documents\WindowsPowerShell\CtrlCEnabler.dll"
    3. [CtrlCEnabler]::EnableCtrlC() > $null

After this instruction, the PowerShell console always enables Ctrl + C break, even when launched from Visual Studio’s external tools menu.

How does it work?

This class library just calls the SetConsoleCtrlHandler Win32 API.

  1. public static bool EnableCtrlC()
  2. {
  3. return SetConsoleCtrlHandler(null, false);
  4. }

See also:

LICENSE

The Unlicense

Appendix

In some case, a PowerShell console, which is launched from Visual Studio IDE external tools menu, doesn’t accept Ctrl+C.

A PowerShell console, which launced by “Open Command Line” Visual Studio IDE Add-in, is alyways available Ctrl+C break.