I'm trying to register an (older) C++ Windows Service from PowerShell with this code
$ProgramDirectoryInstallBin = "c:\dev\bin" $ServiceExe = Join-Path $ProgramDirectoryInstallBin "myservice.exe" $Argument = "-service" Start-Process -FilePath "$ServiceExe" -ArgumentList $Argument -Wait -WorkingDirectory "$ProgramDirectoryInstallBin"
It launches the program fine, but when you look at the actual Command line passed to the program, it has an extra space at the end; e.g., "c:\dev\bin\myservice.exe -service "
and of course the C++ command line parser (straight from the C++ Wizard IIRC) looks like
if (lstrcmpi(lpszToken, _T("Service"))==0) return _Module.RegisterServer(TRUE, TRUE);
and will skip this logic because of the trailing blank (lpszToken=="service ").
So, once I figured this out, there are number of ways to fix it (amend the C++ program or [Diagnostics.Process]::Start or ...) but I'm wondering:
Is there some reason for parser to append the extra space?
While writing this, I found that
&c:\dev\bin\myservice.exe -service
works fine, so we'll go with that, but I'm still feel like I'm missing something re Start-Process (or the parser in general)
???