/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Get AD info into a nested HashTable from MSH "," Logging your MSH session "," MSH get-dateFormat function "," Working with a Path in MSH "," MSH MSN Instant messenger project (broken off) "," Running (Un-block) a downloaded script in MSH "," Timing the loading of your profile in MSH "," Tuning MSH in your Profile "," Einstein 2 + subtopic. "," Burn MSH ?? "," ")

Friday, December 02, 2005

 


getting an Inputbox in MOnad



As MSH has no inputbox function,

you can ofcourse make your own Form :
(I have a couple of example on my blog).

I have three ( 2 of them usable) other possibilities

1) you can use the VB.NET inputbox but it has also the Focus Problem, you see with windows froms in MSH (I solve it with a Form by setting it TopMost, but that is here not possible as it already is fired).
So as this would be the most simple method, the inputbox staying out of focus (hidden) is making it almost useless.

MSH>[reflection.assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
MSH>$r = [Microsoft.VisualBasic.Interaction]::inputbox("Enter :","title")
MSH>$r
input


2) or you can use VBscript, that handles the focus right.

make this vbscript :

'InputBox.vbs
a = inputbox(wscript.arguments(0),wscript.arguments(1))
wscript.echo a


Make following Function :

MSH>function inputbox {cscript //nologo G:\Monad\inputbox.vbs $args[0] $args[1]}


Use like this.

MSH>inputbox "enter" "title"
input

and Add errorhandling as you like ;-)

the Vbscript way is the most simple.

3) or you can do the .NET part and compile it to an exe.

run this MSH script :

# Compile-VB.msh
# VB.Net .Exe Generator
# /\/\o\/\/ 2005

$provider = new-object Microsoft.VisualBasic.VBCodeProvider
$params = new-object System.CodeDom.Compiler.CompilerParameters
$params.GenerateExecutable = $true
$params.GenerateInMemory = $False
$refs = "System.dll","Microsoft.VisualBasic.dll","System.Data.DLL"
$params.ReferencedAssemblies.AddRange($refs)
# VB.NET EXAMPLE
$txtCode = @'
Imports Microsoft.VisualBasic
Imports System
Module Module1
  Sub Main(ByVal strArgs() As String)
    dim result as string
    result = inputbox(strargs(0),strArgs(1))
    console.writeline(result)
  End Sub
End Module
'@
$results = $provider.CompileAssemblyFromSource($params, $txtCode)
$results



TempFiles : {C:\Documents and Settings\mow\Local Settings\Temp\2heysyo7.exe}
Evidence :
CompiledAssembly : 2heysyo7, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Errors : {}
Output : {}
PathToAssembly : C:\Documents and Settings\mow\Local Settings\Temp\2heysyo7.exe
NativeCompilerReturnValue : 0

MSH>& 'C:\Documents and Settings\mow\Local Settings\Temp\2heysyo7.exe' "test" "title"
lol

As you can see I did not use a Filename, You can copy it out of the Temp folder,
then you can rename the generated exe and use it then.
(this keeps it General, you can just past in some VB.net Code and compile it.)

generating a Class in Memory and then start it from MSH, as I may have seen in some of my former blog entries, will not work in this case as then we have got the focus problem again.

MSH>$r = G:\Monad\Inputbox.exe "test" "title"
MSH>$r
input

using a compiled EXE is the way I use from MSH (whith parameter and errorchecking that is ;-))

b.t.w. I also have the "Form version" as the only way the Inputbox shows that the Cancel button is pushed is that the return value is emply, some ones makeing a form for this also has his advantages (especialy if you have VS handy).

also it's on my list of "CMDlets to be...", so maybe it will make this blog sometime ;-)

enjoy,

gr /\/\o\/\/


Comments: Post a Comment



<< 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?