Simple InputBox function

前端 未结 3 1270
逝去的感伤
逝去的感伤 2020-12-08 10:53

I\'m aware of a simple pop-up function for PowerShell, e.g.:

function popUp($text,$title) {
    $a = new-object -co         


        
3条回答
  •  囚心锁ツ
    2020-12-08 11:51

    It would be something like this

    function CustomInputBox([string] $title, [string] $message, [string] $defaultText) 
    {
    $inputObject = new-object -comobject MSScriptControl.ScriptControl
    $inputObject.language = "vbscript" 
    $inputObject.addcode("function getInput() getInput = inputbox(`"$message`",`"$title`" , `"$defaultText`") end function" ) 
    $_userInput = $inputObject.eval("getInput") 
    
    return $_userInput
    }
    

    Then you can call the function similar to this.

    $userInput = CustomInputBox "User Name" "Please enter your name." ""
    if ( $userInput -ne $null ) 
    {
     echo "Input was [$userInput]"
    }
    else
    {
     echo "User cancelled the form!"
    }
    

    This is the most simple way to do this that I can think of.

提交回复
热议问题