jeudi 14 mars 2013

Clear clipboard from the Windows PowerShell command line

I convert a bunch of slide decks to word processor handouts used in our trainings. Since there are over 100 decks and powerpoint ends up using Gb's of RAM once it has finished and is doing nothing anymore, I thought I would clear the clipboard.

Tangent: something uses Gb's of RAM and remains idle? Sounds like Microsoft hired some SAP developers.

Anyway, this is how I chose to solve the problem in a nice powershell script:

$a = [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$b = [Windows.Forms.Clipboard]::Clear()


To run this, you must start powershell.exe single-threaded:

powershell -sta myscript.ps1

BTW, sounds strange that powershell starts multi-threaded by default, however, it makes absolutely no sens at all that powershell cannot run this single-threaded shit in a multi-threaded instance.

I can understand that you cannot run multi-threaded shit in a single-threaded instance of powershell, makes sense, but the opposite is just plain fucked up, no ifs, buts, or maybes.


Enjoy