/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Some Monad Com hacks "," It's busy at the Monad front "," Monad Remoting "," How MSH Works "," Hosting an MSH runspace from Monad "," MSH get-WmiMethodHelp function Update 3 "," out-dataGrid function for Monad "," Windows "Monad" Shell (MSH) Beta 3.1 "," Windows "Monad" Shell (MSH) Beta 3.1 "," scripting games Last Day MSH answers for event 7 a... "," ")

Monday, March 27, 2006

 


VBscript hosting in MSH, Inputbox in Monad part 2



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 :


Comments:
Anonymous Anonymous
Gutten TAG!
Keep up this great resource.
Very much interesting site. You have to look at this too.

I know another good sites:
http://personalloanscom.blogspot.com/ personal loans

Aufiderzein!
 
Anonymous Anonymous
Gutten TAG!
I bookmark your site, best greetings.
Very much interesting site. You have to look at this too.

Another links here:

http://insurancequotes-com.blogspot.com/ insurance quotes

Ciao!
 
Anonymous Anonymous
Hi
Keep up this great resource.
Very much interesting site. You have to look at this too.

Also visit my sites:

http://tramadol-one.blogspot.com/ tramadol

Thank's!
 
Anonymous Anonymous
salute!
Very like it!
Very much interesting site. Here a lot of helpful information.

Try this - very useful:

http://ephedra-on.blogspot.com/ ephedra

Aufiderzein!
 
Post a Comment

Links to this post:

Create a Link



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?