The Best April Fools Blog Post
I just happened across this :-)
PowerShell Gadget 1.1 Released
See my dedicated PowerShell Gadget page for details.
Using .NET Components from Vista Sidebar Gadgets
Sometimes, when developing a non-trivial gadget, you need the full power of good old .NET. Fear not, with just a little bit of tasty COM Interop, .NET components can be successfully used from a gadget.
STEP 1 - Create your .NET component
[ComVisible(true)] public interface IMyComponent { void DoStuff(); } [Guid("31267db9-1912-4524-a757-4224b70d0282")] [ProgId("Mindscape.MyComponent")] [ClassInterface(ClassInterfaceType.None)] [ComVisible(true)] public sealed class MyComponent : IMyComponent { void DoStuff() { // yep, doing stuff... } }
STEP 2 - Register your .NET component
First, ensure your assembly is signed.
Either:
- Run regasm.exe <My.DotNet.dll> /codebase. Or,
- Or check “Register for COM Interop” in the Project Properties/Build tab. Or,
- Include gadget code to self-register the component. More to come on this…
STEP 3 - Consume your component from the gadget
Either:
Create your component using new ActiveXObject:
var myComponent = new ActiveXObject("Mindscape.MyComponent"); myComponent.DoStuff();
Create your component using the object tag. This seems to be required to have the gadget handle events from the component. More to come on this.
<object id="myComponent" classid="clsid:31267db9-1912-4524-a757-4224b70d0282"></object>
In upcoming posts I plan to cover in a bit more detail event handling and component self-registration.
Hope this helps.
PowerShell Gadget
UPDATE: The gadget now has a dedicated page
Introducing my first gadget. I started this partly just to see if it could be done and partly because I thought it might be something that I would use. The good news is that (four complete rewrites and too many late nights later) I was right on both counts.
The gadget runs in two modes
- Normal (non-flyout mode) commands may be entered directly into the gadget in the Sidebar. E.g. enter Notepad and hit enter and notepad opens up.
- Flyout mode, the whole console window is displayed as per the screenshot above. To toggle flyout mode click on the small blue PowerShell icon on the gadget.
The gadget console window is just a hosted instance of PowerShell.exe so you can change the font, colors etc. in the normal way. To get to the console properties window just click the button on the gadget settings dialog.
Enjoy. (Any and all feedback appreciated).
UPDATE: This gadget requires PowerShell installed to the default location. :-)
UPDATE: Having more than one instance of the gadget open is broken. I am investigating.




