2

I am scheduling a task from a WPF application using a PowerShell script but whenever this scheduler runs it blinks up the powershell window and goes within seconds.

I have already added arguments like this:

-WindowStyle Hidden -Execution Policy Bypass - NoProfile -File C:test.ps1

Even after adding -WindowStyle Hidden it is not hiding the console. How to hide this console window?

I can't use a VB script as we are checking some conditions in a PowerShell script while scheduling the task. So is there any way we can disable or hide this window?

Itchydon
  • 2,572
  • 6
  • 19
  • 33
Shivani G
  • 71
  • 2
  • 13
  • 1
    Probably just a typo - you have a gap betwee the `-` and the `NoProfile` instead of `-noProfile`. The gap existed prior to me editing the formatting – Itchydon Mar 28 '22 at 11:11
  • Does this answer your question? [How to hide the PowerShell window when running a .ps1 script in Task Scheduler?](https://stackoverflow.com/questions/46808635/how-to-hide-the-powershell-window-when-running-a-ps1-script-in-task-scheduler) – iRon Mar 28 '22 at 12:53
  • @iRon I have already gone through this. Doesn't help – Shivani G Mar 28 '22 at 13:12
  • 1
    You could try running `conhost --headless "powershell -WindowStyle Hidden -Execution Policy Bypass - NoProfile -File C:test.ps1"`. It's a bit of a hack, but it's a tried an true method that's worked for me for various things. Make sure the executable that task scheduler is launching is `conhost` and the first argument is `--headless`. – Shenk Mar 28 '22 at 13:48
  • @Shenk can you please elaborate it in depth. You can suggest some examples to run the conhost – Shivani G Mar 29 '22 at 06:24
  • Looks like I didn't fix the spacing problem between `-` and `NoProfile` in my comment. Anyway, for example of the Action of the scheduled task: "Action:" = "Start a program". "Program/script" = "C:\Windows\System32\conhost.exe". "Add arguments (optional):" = "--headless adb.exe -a -P 5037 server nodaemon". "Start in (optional):" = "C:\Android\sdk\platform-tools" – Shenk Mar 29 '22 at 19:17

0 Answers0