This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
In the comments of my last post Jeffrey Snover, made my com example for a fileOpen-dialog into a complete function (.
As I did say in my comment the reason this is handy is that .NET forms do not get the focus when they are started and are hidden (for a workaround for a form see :
out-dataGrid function for Monad ) but for a .NET dialog I have no solution yet, so that function is very handy
*note* in some other GUI examples on my blog I use the topmost = $true method, this is not that elegant, and more important not working anymore since beta 3.you should replace the method in those scripts.before I also did some hacks to get an inputbox from MSH,
getting an Inputbox in MOnad,
also in the Newsgroup thread :
MSH - Is it possible to show a message box and and get input ... James Truher made the vbscript solution a bit cleaner with genarating a temp file.
But using Com and the MSScriptControl, I found yet a better way :
# get-inputBox
# Inputbox from MSH using MSScriptControl
# /\/\o\/\/ 2006
# http://mow001.blogspot.com
function get-input {
param ($message = "Input : ",
$Title = "Inputbox")
$vbs = new -com MSScriptControl.ScriptControl
$vbs.language = 'vbscript'
$vbs.addcode("function getInput() getInput = inputbox(`"$message`",`"$title`") end function")
$result = $vbs.Eval('getInput')
$result
}
you can add the functions you need with addcode() and than call them with eval() to get the result.
As you can see in the msgbox example below, if you do not need the input back
you can just use ExecuteStatement method, but to get a value back you need to wrap it into a function and use the eval method, like in the inputbox function
# make control
$vbs = new -com MSScriptControl.ScriptControl
$vbs.language = 'vbscript'
# display msgbox :
$vbs.ExecuteStatement('msgbox "Hello MSH World",,"Message from VBscript"')
# Vbscript evaluations and functions
$vbs.Eval('2^16')
$vbs.Eval('strreverse("This is a test string.")')
this eval method is "normaly" to evaluate expressions using vbscript :
(so you can use al the vbscript math functions you are used to, also very handy ;-) )
thats why we wrap the inputbox in get-input into a function, to be able to use it with eval().
b.t.w. the last line above is also another solution to the last question in the scripting games,
2006 Winter Scripting Games (part 2) ,
if you can't beat them, join them ;-)b.t.w. you do not have access to the Wscript object, so for example wscript.echo will not work, you need cscript for that, but for the rest you have the full vbscript access, or jscript, or even python I think if its registered (not tried that).
Enjoy
greetings /\/\o\/\/
Tags : Monad msh