0

I have created a task in task scheduler.

Its basically a powershell script which has to run in interactive mode.

Task is running under SYSTEM account.

In Actions tab, under Program/Script I have added path of the ServiceUI.exe e.g, C:**\ServiceUI.exe Under Add arguments option, I have added C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -Windowstyle hidden -NoProfile -Executionpolicy bypass -file "C:**\PS1.ps1"

When I run the task, powershell window prompt shows for a fraction of a second.

Could someone please suggest a way to hide it?

Rajneesh Jha
  • 11
  • 1
  • 7
  • Yes this is a long standing complaint. https://stackoverflow.com/questions/1802127/how-to-run-a-powershell-script-without-displaying-a-window – js2010 Sep 27 '21 at 12:29
  • Yes, I have see that, and tried quite a few of the solutions mentioned in the link. However, it still doesn't work. Only difference I could find is, my task is rununning ServiceUI.exe as program'script in the Actions tab, and all other commands are added as arguments. Am I missing somethign here, or can it be doen in a different way. – Rajneesh Jha Sep 27 '21 at 13:39
  • The one using vbscript works for me. – js2010 Sep 27 '21 at 13:48
  • Thanks, using vbscript worked fine. – Rajneesh Jha Sep 28 '21 at 12:39

1 Answers1

0

I was able to fix the problem by using vb script.

WScript.Quit CreateObject("WScript.Shell").Run("powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File " & PSscriptPath, 0, true)

In Actions tab, under Program/Script I had path of the ServiceUI.exe e.g, C:**\ServiceUI.exe

Added wscript.exe "vbs script path" in the arguments option.

Powershell prompt doesn't come up, and task works perfectly in interactive mode under SYSTEM account using these options.

Rajneesh Jha
  • 11
  • 1
  • 7