FancyPrairie
Programmer
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):
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)
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?
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?