1

I'd like to input variable using GUI on remote windows machine. I tried to run Powershell input box command using run_ps in winrm.

Add-Type -AssemblyName Microsoft.VisualBasic;
$value = [Microsoft.VisualBasic.Interaction]::InputBox('Enter group name', 'XA Group', '')

On remote machine it not showing input box when i try to run from local machine. Is there any way i can run this powershell input box command in winrm , or any other method to input variable using GUI in remote machine?

1
  • You'd have to run it under the users context that's logged in Commented Jul 30, 2021 at 13:43

1 Answer 1

1

Using GUI elements in a PowerShell remoting session isn't supported, because the server component that services the caller's request runs in an invisible window station and the remoting protocol is solely based on communicating the output from PowerShell commands (including output from non-interactive console programs) back to the caller:

  • In the case of calling the [Microsoft.VisualBasic.Interaction]::InputBox() method, the method itself detects that it is running in an invisible window station and emits the following error message:

    • Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.[1]
  • In other cases, such as trying to launch notepad.exe, the failure may be silent (process creation may succeed, but nothing ever becomes visible, and the process may shut itself down shortly after creation).

You can try one of the following workarounds:

  • Present the GUI element on the client side before invoking the remoting command, and pass the result as an argument to the remote command.

  • Use the console-based Read-Host cmdlet instead.

    • Note: External programs that prompt the user for input are not supported in remoting sessions, even if they prompt in the console; e.g., cmd /c 'set /p foo="Enter something: "' instantly returns instead of prompting.

[1] The workaround suggested by this error message does not work in remote sessions; if it were effective, the dialog would uselessly display on the server; what actually happens if you call with such a style (directly via [System.Windows.Forms.MesssageBox]::Show(), given that [Microsoft.VisualBasic.Interaction]::InputBox() doesn't support specifying these styles) is that no dialog is shown and the default-button response is instantly returned.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.