2

If I paste this into Powershell blue window it runs fine and launches the program

Start-Process “C:\Program Files (x86)\Engine Pro\engine.exe” -ArgumentList "#21#”;

but if I try to run the same command in a script, run.ps1 script, that launches from a scheduled task in Windows, it does nothing

PowerShell.exe -windowstyle hidden -NoProfile -ExecutionPolicy Bypass C:\run.ps1

Does it have something to do with the -ExecutionPolicy Bypass? Do I have to have an Execution policy in the script as well? I really don't know what that is. I know what -windowstyle hidden is but -NoProfile -ExecutionPolicy Bypass I'm not sure why that is there, just found it on another page, but it's all working except for the program launching from within the script.

Thank you.

mklement0
  • 382,024
  • 64
  • 607
  • 775
Kurt L.
  • 623
  • 10
  • 23
  • 1
    Your command uses Unicode (non-ASCII) double quotation marks; unless you save your `*.ps1` files as UTF-8 _with BOM_ (or as UTF-16LE), PowerShell will misinterpret it. – mklement0 Dec 24 '18 at 18:48
  • Depending on your PowerShell Version (below 6/core) the default is `-Command` not `-File`, so you may need to use `PowerShell.exe -windowstyle hidden -NoProfile -ExecutionPolicy Bypass -File C:\run.ps1` –  Dec 24 '18 at 19:18
  • The whole script works with the " " on everything, but when I try to launch a program from within the scritp it just does noting. Im using " " and editing the file with coding program ATOM 1.33.1 x64. Adding -File did nothing. I thought it might be BitDefender but I switched that off and stiff the program is not launching. I tried launching notepad.exe from the script and that doesn't launch either. Not sure what's happening. – Kurt L. Dec 24 '18 at 19:53
  • Stupid me, It was the & symbol. Ive seen it on hundreds of threads already. `& Start-Process "C:\Program Files (x86)\Engine Pro\engine.exe" -ArgumentList "#21#";` worked, Took a while it figure it out. Thanks everyone – Kurt L. Dec 24 '18 at 20:24

1 Answers1

0
& Start-Process "C:\Program Files (x86)\Engine Pro\engine.exe" -ArgumentList "#21#";
Kurt L.
  • 623
  • 10
  • 23
  • 3
    The invocation operator (`&`) is superfluous here. – Bill_Stewart Dec 24 '18 at 21:49
  • 3
    To elaborate on @Bill_Stewart's comment: The absence of `&` before your `Start-Process` call cannot be the source of your problem as described in your question, because whether or not you place `&` before `Start-Process` makes no difference. `&` is only _needed_ if the command name / path is specified in _quotes_ and/or via a _variable reference_. – mklement0 Dec 25 '18 at 02:08
  • Oh, Even with the -ArgumentList bit? The line above it the exact line I am using and it is working. So I'm not going to fool around with it at this time. I wonder what the problem was then, It seams to have been fixed by something I did. I will revisit this soon, I had to try to get this working before Christmas and something I did fixed it. The script now launches the program as I wanted it too. Thank for your support. Maybe it was Bit Defender threat defence, I turned that off and then put in an exception for Powershell.exe and x64 Powershell.exe. That was blocking it I noticed as well. – Kurt L. Dec 25 '18 at 21:14