::::::::: PowerShell :::::::::
Wednesday, November 30, 2005
  PDC05 Hands-On Lab on Creating Monad Providers
what is "PDC05 Hands-On Lab on Creating Monad Providers" you ask? It is one of the Word doc that comes with MSH Beta 2 documentation.

Hmm.. I must say that it is really darn good of a tutorial for dealing with creating a new provider for MSH...
The lab basically deals with creating a new MSH provider for accessing MDB file(Microsoft Access DB) as if it were a local filesystem.


It is possible to implement the provider to handle all the basic MSH core commands(help page available through "get-help about_core_commands" on the MSH prompt), such as "get-childitem"(aliased as "ls" or "dir"), "get-content"(aliased as "gc"), "set-localtion"(aliased as "cd"), and etc...


Some of the implementations for features like deleting(implementing "RemoveItem" for "NavigationCmdletProvider"), adding("NavigationCmdletProvider.NewItem") and updating Access DB data are intentionally left out for people to try to implement.


Overall, spending 2~3 hours on this lab was surely worth it.

 
Saturday, November 12, 2005
  [MSH] Disposing COM object.
I had a problem with this "Speak" function I had posted on 11/08/2005, Here

The problem was that, "Speak" function did not dispose the excel object create so even after MSH was exited, the COM object would still be alive and could be seen in Task Manager. So i hit the Newsgroup and have found the answer(Thanks to both "Jouko Kynsijärvi" and "Keith Hill") on how to dipose that darn COM object.


Keith Hill
Nov 12, 12:55 pm show options

Newsgroups: microsoft.public.windows.server.scripting
From: "Keith Hill" - Find messages by this author
Date: Sat, 12 Nov 2005 10:55:39 -0700
Local: Sat, Nov 12 2005 12:55 pm
Subject: Re: [MSH] How to dispose a COM object
Reply | Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse


"Jouko Kynsijärvi" wrote in message


news:%23pf9pW65FHA.2040@TK2MSFTNGP14.phx.gbl...


> You can release the COM object by using Marshal.ReleaseComObject():



Keep in mind that if you marshal a COM object back and forth between
different COM servers and MSH, the ref count on the RCW can get bumped up
past 1. That means that if you really, really want to get rid of the COM
object you typically do this:

while
([System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComOb­ject]$excel)
-gt 0) {}


Essentially ReleaseComObject returns the new ref count and you want to
continue calling it until the ref count reaches 0. At least this was the
way it worked in .NET 1.1. And indeed the .NET 2.0 docs say:


Note
To ensure that the runtime callable wrapper and the original COM
object are released, construct a loop from which you call this method until
the returned reference count reaches zero.


Yeah I've been bit by this issue before.


--
Keith
 
  [Non-MSH] Stupid function practice
As I was browsing MSDN2 website to see if there is any useful classes and function I could use to maintain SQL 2000 server or my comp.

I have come across a namespace Microsoft.SqlServer.Server.

Ah, great, there should be a lot of fun stuff in it.
So I thought.

But i ran into this rather interestingly named function ExecuteAndSend of SqlPipe class.

AFAIK, a function should do ONE thing and ONE thing only, WELL.
Is it that hard to write a code like

SqlContext.Pipe.Execute(); 
SqlContext.Pipe.Send();

// Instead of
SqlContext.Pipe.ExecuteAndSend();


BTW, this "ExecuteAndSend" reminds of "SendAndExit"(i think i saw something like this from Outlook) and "SaveAndExit" functionality in Crystal Reports Formula Editor

I tend to despise such a coding practice...
 
Friday, November 11, 2005
  Show Desktop in MSH way
Ok, I have modified "/\/\o\/\/" yet further.
I have lost that darn "show desktop" button and it was a pain in the ass to get it back on to my "quick launch". Ah, and yeah, when i program, I need to title windows either horizontally or vertically so that i could compare two code side by side.

But oh well, to tile windows, i had to select windows one by one pressing controls and then title'em all... So i created another MSH script that do just what I mentioned.

There are many options that Shell.Application offers and I will be extending this script to support all the functionalities that Shell.Application offers...


# ShellUtil.msh
# author: dance2die
# original code author: /\/\o\/\/# date: 11/11/2005 @ 08:51PM


[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")

function ShellUtil {

$shell = new-object -com shell.application

$form = new-object System.Windows.Forms.form
$cm = new-object System.Windows.Forms.ContextMenu
$mi = new-object System.Windows.Forms.MenuItem
$ni = new-object System.Windows.Forms.NotifyIcon


# Display "Show Desktop" menu
$miToggle = new-object System.Windows.Forms.MenuItem
$miToggle.Index = 0
$miToggle.Text = "&Show Desktop"

# Display "Minimize All" menu
$miMinAll = new-object System.Windows.Forms.MenuItem
$miMinAll.Text = "&Minimize All Windows"
$miMinAll.Index = 1

# Display "Undo Minimize All" menu
$miUndoMinAll = new-object System.Windows.Forms.MenuItem
$miUndoMinAll.Index = 2
$miUndoMinAll.Text = "&Undo Minimize All Windows";

# Display "Tray Properties" menu
$miTrayProps = new-object System.Windows.Forms.MenuItem
$miTrayProps.Index = 3
$miTrayProps.Text = "&Tray Properties..."

# Display "Cascade Windows" menu
$miCascade = new-object System.Windows.Forms.MenuItem
$miCascade.Index = 4
$miCascade.Text = "&Cascade Windows"

# Display "Tile Horizontally" menu
$miTileH = new-object System.Windows.Forms.MenuItem
$miTileH.Index = 5
$miTileH.Text = "Tile Windows &Horizontally"

# Display "Tile Vertically" menu
$miTileV = new-object System.Windows.Forms.MenuItem
$miTileV.Index = 6
$miTileV.Text = "Tile Windows &Vertically"

# Display "Exit" menu
$miExit = new-object System.windows.Forms.MenuItem
$miExit.Index = 10
$miExit.Text = "E&xit"


$form.contextMenu = $cm
$form.contextMenu.MenuItems.Add($miToggle)
$form.contextMenu.MenuItems.Add($miMinAll)
$form.contextMenu.MenuItems.Add($miUndoMinAll)
$form.contextMenu.MenuItems.Add($miTrayProps)
$form.contextMenu.MenuItems.Add($miCascade)
$form.contextMenu.MenuItems.Add($miTileH)
$form.contextMenu.MenuItems.Add($miTileV)
$form.contextMenu.MenuItems.Add($miExit)


$form.ShowInTaskbar = $False
$form.WindowState = "minimized"
$form.add_Closing({ $form.ShowInTaskBar = $False })

$ni = $ni
$ni.Icon = New-object System.Drawing.Icon("c:\programming\msh\icons\test.ico")
$NI.ContextMenu = $cm
$NI.Text += "Shell Utility";

$tipTitle = "Bah"
$tipText = "Bah"

$miToggle.add_Click({
$shell.ToggleDesktop()
$tipTitle = "Show Desktop"
$tipText = "Toggle Desktop..."
})
$miMinAll.add_Click({
$shell.MinimizeAll()
$tipTitle = "Minimize All..."
$tipText = "Minimize All windows..."
})
$miUndoMinAll.add_Click({
$shell.UndoMinimizeAll()
$tipTitle = "Undo minimize all"
$tipText = "Undo minimize all"
})
$miTrayProps.add_Click({
$shell.TrayProperties()
$tipTitle = "Display Tray Properties"
$tipText = "Modify system tray properties..."
})
$miCascade.add_Click({
$shell.CascadeWindows()
$tipTitle = "Cascade windows"
$tipText = "Cascade all windows"
})
$miTileH.add_Click({
$shell.TileHorizontally()
$tipTitle = "Tile Horizontally"
$tipText = "Tile windows horizontally"
})
$miTileV.add_Click({
$shell.TileVertically()
$tipTitle = "Tile Vertically"
$tipText = "Tile windows vertically"
})
$miExit.add_Click({
$form.Close()
$NI.visible = $false
})

$ni.ShowBalloonTip(0, $tipTitle, $tipText, [System.Windows.Forms.ToolTipIcon]"Info")

$NI.Visible = $True
$form.showDialog()
}


ShellUtil
 
Wednesday, November 09, 2005
  Speak, your mind... In Excel that is...
I think what i am posting is quite old of a stuff.
But oh well... Like I care...

Let excel "speak" what you type...

function speak {
param([string] $text = "Hello, World!")

$ex = new-object -com excel.application
$ex.speech.speak($text, $null, $null, $null)
}



now,


MSH> speak "your mind..."


Oh yeah, the problem is that, after each "speak", an instance of "excel" will be shown on your Task Manager. So if you would like to spam "speak", create an instance of excel object "outside" of function speak, then use that excel object repeately.

Bah, i am not sure how to dispose that $ex when it's out of scope of function speak yet. I thought it was gonna be done automatically... I guess i should mess around with scope, tomorrow...
 
Tuesday, November 08, 2005
 
/\/\o\/\/ on MSH (Monad): MSH start. Function

Another fun msh script by "/\/\o\/\/".

Here is a bit modified version that I have put on my "profile.msh".
This one basically takes a directory to open Windows Explorer for.
Default is the current directory so...


# original code author: /\/\o\/\/ 
function startHere {
param([string] $dir = (pwd).path)

$sh = new-object -com shell.application
$sh.explore($dir)
}
 
Monday, November 07, 2005
  Displaying Weather Info through RSS with MSH
Uhm, I have been trying to display Weather data through MSH scripting.
Man, after struggling for 30 minutes, i got kind of tired and didn't event get to finish the fully working demo.

I just have pasted something i have been fiddling around a bit(WARNING: hardcore hardcoding)

Most of Form window code was copied from MSH directory watcher with popup-balloon and RSS part can be found from Monad and RSS, Part 2

I was having trouble with getting a description for each "$rssData.rss.channel.item". The description was in "CData" form and it wouldn't let me access the property named "#cdata-section". I guess i just don't know how to access the property... Bah, time to go and hit the usenet...


[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")

function weather {
$form = new-object System.Windows.Forms.Form
$cm = new-object System.Windows.Forms.ContextMenu
$miExit = new-object System.Windows.Forms.MenuItem
$miRefresh = new-object System.Windows.Forms.MenuItem
$ni = new-object System.Windows.Forms.NotifyIcon

$form.ContextMenu = $cm
$form.ContextMenu.MenuItems.Add($miRefresh)
$form.ContextMenu.MenuItems.Add($miExit)
$form.ShowInTaskbar = $false
$form.WindowState = "minimized"
$form.add_Load({
$wc = new-object System.Net.WebClient
$uri = "http://weather.msn.com/RSS.aspx?wealocations=wc:USNY0833&weadegreetype=F"
$rssData = [xml] $wc.DownloadString($uri)

$title = $rssData.rss.channel.title
$desc = $rssData.rss.channel.item[0].title

$ni.ShowBalloonTip(100, $title, $desc, [system.windows.forms.ToolTipIcon]"Info")
})

$ni = $ni
$ni.Icon = new-object System.Drawing.Icon("c:\msh\icons\test.ico")
$ni.ContextMenu = $cm

$miRefresh.Index = 0
$miRefresh.Text = "&Refresh"
$miRefresh.add_Click({
$wc = new-object System.Net.WebClient
$uri = "http://weather.msn.com/RSS.aspx?wealocations=wc:USNY0833&weadegreetype=F"
$rssData = [xml] $wc.DownloadString($uri)

$title = $rssData.rss.channel.title
$desc = $rssData.rss.channel.item[0].title

$ni.ShowBalloonTip(100, $title, $desc, [system.windows.forms.ToolTipIcon]"Info")
})

$miExit.Index = 1
$miExit.Text = "E&xit"
$miExit.add_Click({ $form.Close() })

$ni.visible = $true
$form.showDialog()
}

weather
 
Sunday, November 06, 2005
  MSDN monad blog
I think i will just start checking out the official monad technology blog

Seems quite interesting...

Wait a second.
What about Reskit-MSH

Keeping track with
/\/\o\/\/ is getting harder and harder for him coming up with all the new stuff to play around with...

If you go to MS Scripting on Google Newsgroup, you can see a lot of useful questions posted concerning MSH. Ah, IIRC, the most notable poster seems to be "/\/\o\/\/"
 
Friday, November 04, 2005
  /\/\o\/\/ on MSH (Monad): MSH directory watcher with popup-balloon
/\/\o\/\/ on MSH (Monad): MSH directory watcher with popup-balloon

Now, here is some short, but a very serious script written by /\/\o\/\/

The page basically deals with a script which monitors a directory(which is passed as an argument) for and displays this "Balloon" tip at icon tray when the watching directory has been changed.

If you simply copy and paste the code on that page, it won't work as expected by throwing an error. Ah, gosh, it was because path to an icon file for NotifyIcon object wasn't there(since /\/\o\/\/ had hardcoded it as "g:\monad\mow.ico".

And also if you copy the whole script including the comment, it will generate an error so make sure that you save the whole script either as a file + .msh or copy and paste excluding the comment to run...(hey, but don't forget about who the original author[/\/\o\/\/] of the script is...)


I have modified the code a bit for more events(deleted and created) and also added "Start Monitoring" & "Stop Monitoring" context menu for NotifyIcon($NI in /\/\o\/\/'s code) object.

For feeling a bit buzzed from beer, i will be posting the modified source later.
 
Let's get lazy with PowerShell!

Name:
Location: Flushing, NY, United States

Experimenting with a different format of blogs...

Links
ARCHIVES
10/01/2005 - 11/01/2005 / 11/01/2005 - 12/01/2005 / 12/01/2005 - 01/01/2006 / 01/01/2006 - 02/01/2006 / 02/01/2006 - 03/01/2006 / 03/01/2006 - 04/01/2006 / 04/01/2006 - 05/01/2006 / 05/01/2006 - 06/01/2006 / 06/01/2006 - 07/01/2006 / 07/01/2006 - 08/01/2006 / 08/01/2006 - 09/01/2006 / 10/01/2006 - 11/01/2006 / 11/01/2006 - 12/01/2006 /


Powered by Blogger