Format for a command line with "\"
Having some difficulty sorting out the quotes for this command line to create a scheduled task:
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.
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)
Please log in to answer
Posted by:
captain_planet
14 years ago
These two should work (the latter is probably more readable and better practise):
I've not bothered to look at your paramaters, just your quote issue, so i'll let you go from here......[;)]
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
Posted by:
mturman
14 years ago
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
Posted by:
airwolf
14 years ago
Posted by:
mturman
14 years ago
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.
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
Posted by:
mturman
14 years ago
Posted by:
Jsaylor
14 years ago
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:
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?
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.