Jump to content

Problem creating a Schedule Task


Recommended Posts

I am working on a script to create a schedule task that runs once a month on day 20.

The script creates the task but in the run window it is adding

"C:\Documents and Settings\userid\Desktop\task\'C:\WINDOWS\system32\defrag.exe" %homedrive%

Which causes the task to not run.

I need it to just put in C:\WINDOWS\system32\defrag.exe" %homedrive%.

What am I doing wrong?

Below is the code I am using

runwait ("schtasks /create /RU SYSTEM /SC monthly /D 20 /TN ""Monthly Defrag"" /TR ""'%systemroot%\system32\defrag.exe %homedrive%"" /ST 01:00:00")

Thanks for your help

Link to comment
Share on other sites

I am working on a script to create a schedule task that runs once a month on day 20.

The script creates the task but in the run window it is adding

"C:\Documents and Settings\userid\Desktop\task\'C:\WINDOWS\system32\defrag.exe" %homedrive%

Which causes the task to not run.

I need it to just put in C:\WINDOWS\system32\defrag.exe" %homedrive%.

What am I doing wrong?

Below is the code I am using

runwait ("schtasks /create /RU SYSTEM /SC monthly /D 20 /TN ""Monthly Defrag"" /TR ""'%systemroot%\system32\defrag.exe %homedrive%"" /ST 01:00:00")

Thanks for your help

You have an extra single quote right before %systemroot%. If you enclose your statement in single quotes, you can avoid using double-double quotes.

For example:

RunWait('schtasks /create /RU SYSTEM /SC monthly /D 20 /TN "Monthly Defrag" /TR "%systemroot%\system32\defrag.exe %homedrive%" /ST 01:00:00')

Link to comment
Share on other sites

You have an extra single quote right before %systemroot%. If you enclose your statement in single quotes, you can avoid using double-double quotes.

For example:

RunWait('schtasks /create /RU SYSTEM /SC monthly /D 20 /TN "Monthly Defrag" /TR "%systemroot%\system32\defrag.exe %homedrive%" /ST 01:00:00')

That worked,

Thanks for your help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...