PSGlass

I quickly whipped a small new utility for Windows PowerShell earlier today. I had noticed a post on Lifehacker about a tool that will glass Command Prompt windows using Aero (on Windows Vista and up). So I thought to myself, “Why can’t I do the same with PowerShell?” Turns out, I already had some code to glass windows in TV Manager. So I built a small application that will search running processes for any PowerShell windows, and then glass what was found. The result is a fairly nice looking window and a tiny application that runs in your system tray.

PSGlass

Download – Does not require installation but requires Windows Vista or Windows 7

Comments

Josh

Or avoid having anything in memory with this:

#

# Sample script showing how to show and hide

# console windows from PowerShell. It uses in-line

# CSharp code to create a ConsoleHelper class to show

# and hide the console.

#

param ([switch] $hidden, [switch] $glass)

#

# CSharp code for the ConsoleHelper class

#

$code = @'

using System;

using System.Runtime.InteropServices;

public class ConsoleHelper {

private const Int32 SW_HIDE = 0;

private const Int32 SW_SHOW = 5;

[DllImport("user32.dll")]

private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);

[DllImport("kernel32.dll", SetLastError = true)]

public static extern bool AllocConsole();

[DllImport("Kernel32.dll")]

private static extern IntPtr GetConsoleWindow();

public struct DWM_BLURBEHIND {

public int dwFlags;

public bool fEnable;

public System.IntPtr hRgnBlur;//HRGN

public bool fTransitionOnMaximized;

}

[System.Runtime.InteropServices.DllImport("dwmapi")]

private static extern int DwmEnableBlurBehindWindow(IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind);

public static void GlassConsole() {

IntPtr hwnd = GetConsoleWindow();

if (hwnd != IntPtr.Zero) {

DWM_BLURBEHIND blur = new DWM_BLURBEHIND();

blur.dwFlags = 0x00000001;

blur.fEnable = true;

//blur.hRgnBlur;//HRGN

blur.fTransitionOnMaximized = true;

DwmEnableBlurBehindWindow(hwnd, ref blur);

}

}

public static void HideConsole() {

IntPtr hwnd = GetConsoleWindow();

if (hwnd != IntPtr.Zero) {

ShowWindow(hwnd, SW_HIDE);

}

}

public static void NormalConsole() {

IntPtr hwnd = GetConsoleWindow();

if (hwnd != IntPtr.Zero) {

ShowWindow(hwnd, SW_SHOW);

DWM_BLURBEHIND blur = new DWM_BLURBEHIND();

blur.dwFlags = 0x00000001;

blur.fEnable = false;

//blur.hRgnBlur;//HRGN

blur.fTransitionOnMaximized = true;

DwmEnableBlurBehindWindow(hwnd, ref blur);

}

}

}

'@

#

# Only build the assembly if the type doesn't exist

#

# if this statement fails, then the trap handler will

# compile the code

[ConsoleHelper] > $null

$ch = [ConsoleHelper]

trap {

# Get an instance of the CSharp code provider

$cp = new-object Microsoft.CSharp.CSharpCodeProvider

# And compiler parameters...

$cpar = New-Object System.CodeDom.Compiler.CompilerParameters

$cpar.GenerateInMemory = $true

$cpar.GenerateExecutable = $false

$cpar.OutputAssembly = "custom"

$cr = $cp.CompileAssemblyFromSource($cpar, $code)

# display any errors (there should be none...)

if ( $cr.Errors.Count) {

$codeLines = $code.Split("`n");

foreach ($ce in $cr.Errors) {

write-host "Error: $($codeLines[$($ce.Line - 1)])"

$ce | out-default

}

Throw "Compile failed..."

} else {

# don't report the exception

continue

}

}

#

# Now use the helper to show and hide the window...

#

if ($hidden) {

$ch::HideConsole()

} elseif ($glass) {

$ch::GlassConsole()

} else {

$ch::NormalConsole()<


Brent Friedman

Didn't think about doing something like that. Always good to have another option though.


Brent Friedman

Just made a script that extends the glass from the title bar into the window. Set the powershell background to black.

Download

 

PSGlass Script


Itanium

The script file is 404ed. Can you please check the link.


Brent Friedman

Itanium,

Try now, IIS didn't like the extension.


Danny

Sorry Brent, it still gives an 404 on me.

Maybe you can put it in an archive?

Thanks


Brent Friedman

Try now. When I reinstalled IIS, it lost what I had changed.


Danny

Thanks!