0

So I'm trying to run the following code snippet:

start-process -Filepath "c:\support\mbbr.exe" -ArgumentList 'register','–key:ABCDE-ABCDE-ABCDE-ABCDE' -Wait -NoNewWindow

However it stops processing the argument at the colon as it treats it as a reserved character. When I try to escape it with `, it treats the escape character as a normal character and won't let me escape:

Error: –key is an invalid option.

The syntax of register command is:

  register [-key:<prodkey>]

I'm out of ideas, anyone got any clues?

Lorden
  • 1
  • 1

3 Answers3

0

Run it directly seems simplest:

c:\support\mbbr.exe register –key:ABCDE-ABCDE-ABCDE-ABCDE

For waiting, this may be less annoying:

cmd /c start /wait c:\support\mbbr.exe register –key:ABCDE-ABCDE-ABCDE-ABCDE

There's lots of tricks to make powershell wait: How to tell PowerShell to wait for each command to end before starting the next?

js2010
  • 23,033
  • 6
  • 64
  • 66
  • Unfortunately I need the -wait flag in order to run followup commands. Can't have them run asynch. – Lorden Dec 10 '19 at 15:07
  • Problem with cmd is that it still pops up a window while I need it to run hidden. – Lorden Dec 10 '19 at 15:51
  • That link has various other ways to wait, like `| out-null`. Maybe you should update the question saying you want to wait, but don't want a popup window. – js2010 Dec 10 '19 at 19:48
0

Run with invoke-expression and use the 'cmd /c' to catch it when it returns:

invoke-expression "cmd /c c:\support\mbbr.exe register –key:ABCDE-ABCDE-ABCDE-ABCDE"

if you have to run it on remote machines, you'll need to use invoke-command:

invoke-command -computername <remote_hostname> -scriptblock {cmd /c c:\support\mbbr.exe register –key:ABCDE-ABCDE-ABCDE-ABCDE}

HTH

adamt8
  • 308
  • 1
  • 7
  • Same issue here, cmd opens a window and I need to run hidden. – Lorden Dec 10 '19 at 15:53
  • `Invoke-Expression` is not necessary in this case (and in fact, [not recommended](https://devblogs.microsoft.com/powershell/invoke-expression-considered-harmful/)). – Bill_Stewart Dec 10 '19 at 15:55
0

As you noted in your comment, this command should work:

C:\support\mbbr.exe register -key:ABCDE-ABCDE-ABCDE-ABCDE

If the path and/or filename to mbbr.exe contains spaces, use the invocation/call operator (&):

& "C:\Program Files\blah\mbbr.exe" register -key:ABCDE-ABCDE-ABCDE-ABCDE

You shouldn't need Start-Process or cmd.exe.

Since it seems that mbbr.exe still gives an error with the above commands, try quoting its -key argument, as follows:

C:\support\mbbr.exe register "-key:ABCDE-ABCDE-ABCDE"

or this way:

C:\support\mbbr.exe register -key:"ABCDE-ABCDE-ABCDE"

If those commands do not work, it may be that the help message from the executable is incorrect (we can't help with that as we don't have your executable).

Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62
  • After re-testing, `./mbbr.exe register –key:ABCDE-ABCDE-ABCDE-ABCDE` seems to give me the same error of it not listening to the argument after and including the colon. – Lorden Dec 10 '19 at 16:18