Run a single command in an interactive powershell using vagrant winrm

Viewed 44

When running:
vagrant winrm -s powershell -c "[System.Environment]::UserInteractive"

The output is False, the VM is using Windows Server 2019.

An EXE is written to run as a service only if called from a non-interactive context, and runs as an executable if called from an interactive one - we need the output of the EXE, so how do we run a command such that [System.Environment]::UserInteractive is True for the running exe, and the output is received back at the host?

The source code of the app can be similar to this (C#):

if (!Environment.UserInteractive)
    ServiceBase.Run (new Service ());
else
    Start (args);

Extra:

My host is macOS so I can't run vagrant powershell, though that too might have the same issues. I get this when running the EXE using vagrant winrm -s powershell -c "MyApp.exe":

Cannot start service from the command line or a debugger.  A Windows Service must first be installed and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.
0 Answers
Related