masterzen / winrm

Command-line tool and library for Windows remote command execution in Go
Apache License 2.0
425 stars 129 forks source link

Have an option to skip using cmd.exe to execute commands #98

Open rgl opened 5 years ago

rgl commented 5 years ago

Currently the command executable and arguments are executed indirectly by the cmd.exe shell but it would be very useful to have a way to skip it entirely, as that would simplify command execution without having to worry about the cmd.exe parsing rules (this way we "only" need to deal with the default / common CommandLineToArgvW rules).

From what I understood by reading the WinRM/WinRS protocol documentation available as part of [MS-WSMV]: Web Services Management Protocol Extensions for Windows Vista, if we use the http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CustomShell ResourceURI (instead of http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd) we should be able to use any shell.

Have you tried this?

masterzen commented 5 years ago

No I never tried this. It might haven't been documented when I initially wrote this library.

rgl commented 5 years ago

In the mean time I've tried the obvious change of cmd to CustomShell and it did not work. I'm afraid its not that simple to change this, or even possible without implementing some kind of WinRM plugin that handles a CustomShell.

Another alternative would be to use PowerShell Remoting. There's a python library at https://github.com/jborean93/pypsrp (I didn't try to find a ruby equivalent) and by looking at it, the whole thing seems more complex than WinRS/cmd.

Have you tried to use/implement PowerShell Remoting in Ruby?

Another alternative, is to implement something simpler like PowerShell over ssh. Have you though about that?