Avatar of steve-landsaw
steve-landsaw

asked on 

Automating Scheduled Tasks

Here's the scenario:

A specific server, that lives on the xyz domain has two tasks - "enable" and "disable". The task runs under a specific domain user account - xyz\production. This user account has logon rights and has been added to the local admin group on each of the boxes below.

APPSERVER1.xyz.com - this is where the enable and disable tasks live

Servers the sched task will reach out to:
APPSERVER2.xyz.com
APPSERVER3.xyz.com
APPSERVER4.xyz.com
APPSERVER5.xyz.com
APPSERVER6.xyz.com
APPSERVER7.xyz.com

I will log on to APPSERVER1.xyz.com via RDP, with my user account (xyz\user) and manually kick off each of the tasks.
The tasks will call a batch file that goes out to other servers (listed above) on the xyz domain which disables or enables specific scheduled tasks.

Each task on the various boxes above are set to run under varous different xyz domain user accounts.

How can I simply disable the scheduled tasks on the remote boxes without taking the easy way out and stopping the task scheduler service.

I've tried using: schtasks /CHANGE /S \\APPSERVER2.xyz.com /RU xyz\production /RP password /TN "ABC TASK" /DISABLE

But that overwrites the user account info that that tasks runs under with the xyx\production account info.

Could this be done in powershell, vb script, or .NET or? If so, how? I'm desparate here.




ProgrammingMicrosoft DevelopmentMicrosoft Legacy OS

Avatar of undefined
Last Comment
steve-landsaw
Avatar of ErikCamacho
ErikCamacho
Flag of United States of America image

Download pstools

http://technet.microsoft.com/en-us/sysinternals/bb896649

use PSexec to remotely execute your script. you shoudl be able to run it against a text
file of servernames to do multiple at once.
Avatar of bucks
bucks
Flag of Lebanon image

Click Start, type regedit in the Start Search box, and then click regedit.exe in the Programs list.
Locate and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Schedule
In the details pane, right-click the Start DWORD entry, and then click Modify.
In the Value data box, type 4, and then click OK.
Exit Registry Editor, and then restart the computer
Avatar of steve-landsaw
steve-landsaw

ASKER

bucks, that's not an option for me.

ErikCamacho, I've played around with psexec, but I'm trying to automate this process. Any idea how to do that with psexec?
Avatar of steve-landsaw

ASKER

Honestly, I need to do it without psexec. This is a protected environment and I have very little wiggle room.
Avatar of ErikCamacho
ErikCamacho
Flag of United States of America image

If you cannot automate through a script I would use Hyena as the next best thing.

http://www.systemtools.com/hyena/


I think you can download a 30 day trial.

There is some automation you can do through Hyena too.
Avatar of steve-landsaw

ASKER

Yeah, that's not going to work for me either. :/ Sorry. Like I mentioned, there's not a whole lot of room to play.
Avatar of ErikCamacho
ErikCamacho
Flag of United States of America image

Can you run your command through a login script?
Avatar of steve-landsaw

ASKER

Erik, possibly, but that is out of the question, because that would require all of the servers to be rebooted within the maintenance window.
Avatar of steve-landsaw

ASKER

Not to mention all the red tape and explaining.
Avatar of ErikCamacho
ErikCamacho
Flag of United States of America image

Can you make a group policy throw the servers into an group and assign the group to a policy then run Gpudate from the servers in question?
Avatar of steve-landsaw

ASKER

If I do this:
schtasks /Change /S APPSERVER2.XYZ.com /U xyz\production /P password /TN "test" /DISABLE

I get prompted for the password for the user which the "test" task runs under. Is there anyway of getting around that?
Avatar of steve-landsaw

ASKER

If there is a way around that, then I'm golden.
Avatar of steve-landsaw

ASKER

Erik, no changes can be made to the servers or the environment in which they run.
Avatar of steve-landsaw

ASKER

This is a very strict set of circumstances.
Avatar of huacat
huacat

schtasks support two user name and two password.
/U & /P used for schtasks connect to remote server.
/RU & /RP used for the task run under which account at remote server.
Please try give all like below:
schtasks /Change /S APPSERVER2.XYZ.com /U xyz\production /P password /RU task_run_user /RP task_run_password /TN "test" /DISABLE
Avatar of steve-landsaw

ASKER

huacat, that would work if I new for sure what the passwords were for these accounts, but I don't. :/
Avatar of steve-landsaw

ASKER

*knew
Avatar of steve-landsaw

ASKER

And what that does is basically just overwrite the task with whatever is specified in the RU and RP args.
Avatar of huacat
huacat

Can you run ren or move command to rename/move the task?
As we known, the schedule task saved under C:\windows\tasks.
We can rename the .job file extension as others, or move it to another folder(C:\taskbak), then the task disappear, so the task disable.
And we can remove it back to C:\windows\tasks again, the schedule task restore again.
Avatar of steve-landsaw
steve-landsaw

ASKER

Okay, that's strange. I just ran a test utilizing psexec and I was prompted for the password of the account for the scheduled task I am trying to disable - okay, I expected that. When I press enter to get past that, it says access denied, but disables the task anyway.
Avatar of steve-landsaw
steve-landsaw

ASKER

Here's the output from the command line:
C:\TEST>psexec \\TESTAPPSERVER02.XYZ.COM -u xyz\testuseraccount -p testpassword "C:\Program Files\Scheduled Tasks\Test\test.bat"

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

Starting C:\Program Files\Scheduled Tasks\Test\test.bat on TESTAPPSERVER02.XYZ.COM


C:\WINNT\system32>schtasks /CHANGE /TN "test" /DISABLE
Please enter the run as password for "xyz\taskuseraccount":
WARNING: When the run as password is empty, the scheduled task may not run because of the security policy.
ERROR: Access is denied.
C:\Program Files\Scheduled Tasks\Test\test.bat exited on TESTAPPSERVER02.XYZ.COM with error code 1.
C:\TEST>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of steve-landsaw
steve-landsaw

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of steve-landsaw
steve-landsaw

ASKER

This has been given a letter grade of B, because there is still additional coding to be done.
Microsoft Legacy OS
Microsoft Legacy OS

The Microsoft Legacy Operating System topic includes legacy versions of Microsoft operating systems prior to Windows 2000: All versions of MS-DOS and other versions developed for specific manufacturers and Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions, and Windows Mobile.

55K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo