Discussion Locked

How? Create Task Scheduler job in cmd

0 helpful
12 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi everyone

I want to be able to schedule a job in MS Task Scheduler from a batch file. I therefore need to pass parameters such as schedule, command-line, user-credentials, etc.

So far, I've not found a command-line interface to the task scheduler, only the GUI, which is no good to me.

Can anyone help? Does anyone know the format of the .job file?

Thx

12 replies

by rsp

Sorry - all these use the GUI to do the actual scheduling. No good to me!

by lw

If you are on nt/2000/xp you can try

at "command"

e.g.

at 21:00 "net send peter go home"

sends peter the message "go home" at 9 pm.

Enjoy

by rsp

Background: I want to run a batch file that requests username/password to schedule another batch file to run on a "scheduling server" at some period in the future, but under that user context to ensure auditing takes place correctly.

by joseph moore

Well, I do know that if you put the /INTERACTIVE switch with the AT command, it will then build the job and have it run under the authority of the locally logged in user. So, if you can run this from a machine logged in as the user account you want to audit, then adding Interactive will run it under that context. That should do it for you.

Now, the only other thing I can think of to do is to build a BAT file with the commands you want to do, but in the BAT file, use the RUNAS command, and specify the user to run each command as.
For example, a BAT file like this

@echo off
runas /user:MYDOMAIN\JOE NET USE x: \\server\share
runas /user:MYDOMAIN\JOE copy x:\file.txt x:\file2.txt
runas /user:MYDOMAIN\JOE net use x: /delete
EXIT

That should map drive X: to \\server\share under the security context of MYDOMAIN\JOE user account. It then makes a copy of the file x:\file.txt in the same directory and calls the copy file2.txt. Last, the drive mapping is removed. All 3 steps happen under the security context of the JOE account, no matter what account the machine is logged in as.
If you were auditing file creation on the \\SERVER, your Security log in Event Viewer would show JOE doing the file copy. Not another user.

Give that a shot.

by shanghai sam

Hi Joseph

AT /I will run in the same context as the service is set up as, in most cases, SYSTEM, not the logged-on user.

I haven't experimented too heavily, but runas appears to be dependent on the system being W2K.

I don't want to be storing passwords in clear text, so the command has to be scheduled under the context it will run as.

If you think you can help me further, and want more info, drop me an email through the Peer Directory.

Richard

by rsp

AT /I will run in the same context as the service is set up as, in most cases, SYSTEM, not the logged-on user.

I haven't experimented too heavily, but runas appears to be dependent on the system being W2K.

I don't want to be storing passwords in clear text, so the command has to be scheduled under the context it will run as.

This discussion is closed to new replies.