1

I'm trying to have a scheduler to run a Vbscript, which it will run a Powershell script. Basically here is my Vbscript

command = "powershell.exe -nologo -command C:\Users\someuser\Desktop\appAPIMonitor.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0

When I run above script, it worked. But when I place the script at my preferred path, the script wont run as before. So it must be the path not valid. Here is my new script

command = "powershell.exe -nologo -command C:\Users\someuser\My Work\App\Project\My.API.App\Scripts\appAPIMonitor.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0

Can somebody point what is wrong with my path? Is it the whitespace in My Work? Or the dot in My.Api.App?

dausdashsan
  • 241
  • 1
  • 6
  • 16
  • 6
    It's a space, wrap the path in quotes to fix. You need to place double quotes or concat with `chr(34)` to have a double quote in a string. http://stackoverflow.com/questions/2942554/vbscript-adding-quotes-to-a-string – Vesper May 27 '14 at 12:31
  • 1
    Can you put it as answer please? – JPBlanc May 27 '14 at 12:43
  • Here is the code: `command = "powershell.exe -nologo -command ""C:\Users\someuser\My Work\App\Project\My.API.App\Scripts\appAPIMonitor.ps1"""` – Chris May 27 '14 at 13:02
  • well I've tried but still not working. Not sure why, but the script seems not running. Do we really can put the quote around the path? because most of the example don't have it. – dausdashsan May 27 '14 at 14:28
  • 2
    Why are you not just running powershell directly from the task scheduler? – TheMadTechnician May 27 '14 at 16:42
  • I did, previously. But somehow I couldn't totally hide the Window when the task is running (even using -windowstyle hidden). That why I use Vbscript, to hide the window from popping out. – dausdashsan May 28 '14 at 03:22

1 Answers1

0

This is the solution I managed to get.

command = "powershell.exe -nologo -file ""C:\Users\someuser\My Work\App\Project\My.API.App\Scripts\appAPIMonitor.ps1"" "
set shell = CreateObject("WScript.Shell")
shell.Run command,0

Give the last quote some white space and change -command to -file should do the trick. I solve this in my case. Hopefully help anybody in future. By the way, thanks to those who spent their precious time to answer my question.

dausdashsan
  • 241
  • 1
  • 6
  • 16