Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax for SchTasks.exe 1

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
0
0
US
I'm trying to, programmatically, add a task to the Task Scheduler using schtasks. But I can't get the syntax correct. The following code works (note I'm launching db4.mdb):
Code:
Dim objShell As Object
Dim Parameters As String

Set objShell = CreateObject("Wscript.Shell")

Parameters = "/create /sc once /ST 10:30:00 /sd 03/30/2009 /TN test1 /tr e:\dev\db4.mdb"
objShell.Run "c:\winnt\system32\schtasks.exe " & Parameters

However, I need to pass some command line arguments to db4.mdb. So, the command should look like this:
"c:\program files\microsoft office\office11\msaccess.exe" "E:\dev\db4.mdb" /nostartup /x macro1

But I can't get the syntax down. This is what I've tried (plus other things)
Code:
Dim objShell As Object
Dim Parameters As String
Dim strCommand As String

Set objShell = CreateObject("Wscript.Shell")

strCommand = """c:\program files\microsoft office\office11\msaccess.exe"" ""E:\dev\db4.mdb"" /nostartup /x macro1"

Parameters = "/create /sc once /ST 10:30:00 /sd 03/30/2009 /TN test1 /tr " & strCommand
objShell.Run "c:\winnt\system32\schtasks.exe " & Parameters

The above doesn't work. I've read somewhere about using an escape character (\) when there are spaces in the command line arguments, but I haven't been able to get it to work.

Any ideas?
 
Got it to work...looks like this:

strCommand = """""""""c:\program files\microsoft office\office11\msaccess.exe"""""" """"""E:\dev\db4.mdb"""""" /nostartup /x macro1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top