/build/static/layout/Breadcrumb_cap_w.png

Format for a command line with "\"

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

Answers (11)

Posted by: captain_planet 14 years ago
Black Belt
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......[;)]
Posted by: anonymous_9363 14 years ago
Red Belt
0
Isn't there a WMI interface to Scheduled Tasks? That would be a neat way to avoid using SCHTASKS.EXE...
Posted by: mturman 14 years ago
Orange Belt
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?
Posted by: captain_planet 14 years ago
Black Belt
0
"I think you may have misunderstood the question" - you think incorrectly. Have you actually tried any of the examples i posted?
Posted by: mturman 14 years ago
Orange Belt
0
Tried all 3. None worked. Wasn't trying to be rude.
Posted by: airwolf 14 years ago
Red Belt
0
http://msdn.microsoft.com/en-us/library/aa394601(VS.85).aspx

http://msdn.microsoft.com/en-us/library/aa383614(VS.85).aspx
Posted by: mturman 14 years ago
Orange Belt
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.
Posted by: airwolf 14 years ago
Red Belt
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
Posted by: mturman 14 years ago
Orange Belt
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.
Posted by: Jsaylor 14 years ago
Second Degree Blue Belt
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?
Posted by: mturman 14 years ago
Orange Belt
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.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ