Having some difficulty sorting out the quotes for this command line to create a scheduled task:

WshShell.run "%comspec% /c SCHTASKS.EXE /CREATE /TN PCFG /TR "\"C:\Program Files\DSST\PowerCFG 2.5\PCFG.VBE" /SC ONIDLE /I 30 /RU SYSTEM"

It doesn't seem to like the "\ in front of the "C:\Program Files\DSST\PowerCFG 2.5\PCFG.VBE", but it is required for the command line to format properly in the task. I've tried dozens of different quotes, ampersands and chr(34) combinations but no luck so far.

Any assistance would be appreciated.
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
These two should work (the latter is probably more readable and better practise):
WshShell.run "%comspec% /c SCHTASKS.EXE /CREATE /TN PCFG /TR ""C:\Program Files\DSST\PowerCFG 2.5\PCFG.VBE"" /SC ONIDLE /I 30 /RU SYSTEM"or
WshShell.run "%comspec% /c SCHTASKS.EXE /CREATE /TN PCFG /TR " & chr(34) & "C:\Program Files\DSST\PowerCFG 2.5\PCFG.VBE" & chr(34) & " /SC ONIDLE /I 30 /RU SYSTEM"and to go a bit further maybe:
WshShell.run "%comspec% /c SCHTASKS.EXE /CREATE /TN PCFG /TR " & chr(34) & "%ProgramFiles%\DSST\PowerCFG 2.5\PCFG.VBE" & chr(34) & " /SC ONIDLE /I 30 /RU SYSTEM"
I've not bothered to look at your paramaters, just your quote issue, so i'll let you go from here......[;)]
Answered 01/04/2010 by: captain_planet
Third Degree Brown Belt

Please log in to comment
0
Isn't there a WMI interface to Scheduled Tasks? That would be a neat way to avoid using SCHTASKS.EXE...
Answered 01/05/2010 by: VBScab
Red Belt

Please log in to comment
0
From Captain_Planet: I've not bothered to look at your paramaters, just your quote issue, so i'll let you go from here......
My parameters have been tested and are not an issue. As for your suggestions, I think you may have misunderstood the question.

SCHTASKS.EXE /CREATE /TN PCFG /TR "\"C:\Program Files\DSST\PowerCFG 2.5\PCFG.VBE" /SC ONIDLE /I 30 /RU SYSTEM"

Note the path after the /TR switch. Due to the spaces in the path, it must have the "\ in front of "C:\Program Files\..." in order to format properly in the run line of the task that is created. (Don't ask me why...) I've tried using the %ProgramFiles% variable but that doesn't work, either.

Here are some of my attempts:

1) WshShell.run "%comspec% /c SCHTASKS.EXE /CREATE /TN PCFG /TR """\"C:\Program Files\DSST\PowerCFG 2.5\PCFG.VBE""" /SC ONIDLE /I 30 /RU SYSTEM"

2) WshShell.run "%comspec% /c " & ""SCHTASKS.EXE /CREATE /TN PCFG /TR "\"C:\Program Files\DSST\PowerCFG 2.5\PCFG.VBE" /SC ONIDLE /I 30 /RU SYSTEM""

3) WshShell.run "%comspec% /c SCHTASKS.EXE /CREATE /TN PCFG /TR """\"C:\Program Files\DSST\PowerCFG 2.5\PCFG.VBE""" /SC ONIDLE /I 30 /RU SYSTEM""

and about a dozen other combinations.

From VBScab: Isn't there a WMI interface to Scheduled Tasks? That would be a neat way to avoid using SCHTASKS.EXE...

You are correct, however, as far as I can tell, you can only create tasks that run at specific times. I could not find a way to create a task that runs when the system has been idle for a set amount of time. If you know of a way, could you please enlighten me?
Answered 01/05/2010 by: mturman
Orange Belt

Please log in to comment
0
"I think you may have misunderstood the question" - you think incorrectly. Have you actually tried any of the examples i posted?
Answered 01/05/2010 by: captain_planet
Third Degree Brown Belt

Please log in to comment
0
Tried all 3. None worked. Wasn't trying to be rude.
Answered 01/05/2010 by: mturman
Orange Belt

Please log in to comment
0
http://msdn.microsoft.com/en-us/library/aa394601(VS.85).aspx

http://msdn.microsoft.com/en-us/library/aa383614(VS.85).aspx
Answered 01/05/2010 by: airwolf
Tenth Degree Black Belt

Please log in to comment
0
Thanks, airwolf, but I've already visited both those sites numerous times. Been to this one as well: http://technet.microsoft.com/en-us/library/ee176704.aspx

Note: AT API's: Tasks can be run only at specific times (for example, 3:00 P.M. every Tuesday).

I need to create a task that runs on idle.
Answered 01/05/2010 by: mturman
Orange Belt

Please log in to comment
0
Dig a bit deeper under the second link I posted and you'll find http://msdn.microsoft.com/en-us/library/aa380669(VS.85).aspx and http://msdn.microsoft.com/en-us/library/aa383561(VS.85).aspx
Answered 01/05/2010 by: airwolf
Tenth Degree Black Belt

Please log in to comment
0
Bah! Guess I should have mentioned that this is for an XP system. Those idle options are only for Task Scheduler 2.0, which ships with Vista or higher. Thanks anyway.
Answered 01/05/2010 by: mturman
Orange Belt

Please log in to comment
0
If you take a look at captain_Planet's (who is apparently not, in fact, our hero) lines up there, you'll notice that he's showing you how to insert literal quotation marks ("'s) into strings. There are two methods available, you can either 'escape' a quotation mark by using it twice, "", or you can use the literal character chr(34) and concatenate it into your string using the usual ampersands (&'s.) I, and I think most people, greatly prefer the literal chr(34) method for readability purposes.

For instance, the following line:
"Hello " & chr(34) & "human" & chr(34)

Would look like: Hello "human"
when used as a vbscript string.


Do you see how you might use that to inject your required "\" into the script?
Answered 01/05/2010 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
Finally got it working using this:

WshShell.run "%comspec% /c SCHTASKS.EXE /CREATE /TN PCFG /TR " & chr(34) & "\" & chr(34) & "%ProgramFiles%\DSST\PowerCFG 2.5\PCFG.VBE" & chr(34) & " /SC ONIDLE /I 30 /RU SYSTEM",0

Thanks for all your replies.
Answered 01/05/2010 by: mturman
Orange Belt

Please log in to comment
Answer this question or Comment on this question for clarity