SchTasks

Freshman

Registered User.
Local time
Today, 03:46
Joined
May 21, 2010
Messages
437
Hi all,

I'm trying to create a task straight from the command line using the Shell command instead of first creating a batch file and calling that with the Shell command

I'm sure I have a syntax issue somewhere with all the quotes
Can someone help please?

Code:
Shell "C:\Windows\System32\schtasks.exe schtasks /create /tn 'My App' /tr c:\test.txt /sc once /sd 03/12/2015 /st 11:36", vbNormalFocus
 
Seems like the space in my TaskName was the biggest problem

This works:

Shell "schtasks /create /tn MyApp /tr c:\test.txt /sc once /sd 03/12/2015 /st 11:36", vbNormalFocus
 
Need some more help please:

I'm creating my own Command Prompt reminders from a trick I saw on another site.

However the syntax is escaping me:

Shell "schtasks /create /tn MyApp /tr CMD /sc once /sd 03/12/2015 /st 11:36", vbHide

Works 100% but I fail to add parameters or arguments to it

I need to add this string: "/C TITLE Lunch&ECHO Lets eat&TIMEOUT -1" after the CMD call

So I tried lots of combinations of this:

Shell "schtasks /create /tn MyApp /tr CMD /C TITLE Lunch&ECHO Lets eat&TIMEOUT -1 /sc once /sd 03/12/2015 /st 11:36", vbHide

Any ideas?

Thanks
 
If I hard code it into Task Scheduler it looks like the attached screen shot.
So I know if works but just to get it into the Shell command line...
 

Attachments

  • Screenshot_1.jpg
    Screenshot_1.jpg
    22.5 KB · Views: 73
OK - I got it to work by first creating a batch file in VBA on the fly and testing it until it worked.
From that I learned that I should put in 3 X quotes in from and behind the text containing spaces but although I did try it at some point I also had the command and argument split. It worked when I combined it
I then created a Function to use everywhere

Code:
Public Function RemindMe(TaskName As String, StartDate As String, StartTime As String, CmdStr As String)
Shell "schtasks /create /tn " & TaskName & " /tr """ & CmdStr & """ /sc once /st " & StartTime, vbHide
End Function

Public Function DelReminder(TaskName As String)
Shell "schtasks /delete /tn " & TaskName & " /f", vbHide
End Function

Public Function TestCreateRem()
RemindMe "MyApp9", "03/12/2015", "13:15", "CMD /C TITLE Lunch&ECHO Lets eat&TIMEOUT -1"
End Function

Public Function TestDelRem()
DelReminder "MyApp9"
End Function
 
Hi there,
The code I'm using don't seem to work in WinXP (yes some of my Clients still run XP!)
From my Google search it seems like SchTasks was introduced in XP so no reason it should not work.
Any ideas why it is not?

Thanks
 

Users who are viewing this thread

Back
Top Bottom