I have few windows 7 clients whom i need to reboot from windows server . i tried to setup a group policy
Action-create ,Name- Auto shut ,Account-NT/System,Action-shutdown.exe Trigger:4.00 AM :daily
This was applied for OU but it fails to deliver Can someone points where did i went wrong here and how to do it properly??
Have you consider using the command shutdown with the /m switch?
You can create a batch script will all machines you want to reboot
#echo off
for %%a in (computer1 computer2 computer3) do (
shutdown /r /f /m \\%%a /t 30
)
and create a task that executes the script.
schtasks /create /SC DAILY /ST "04:00" /TN "task-name" /RL HIGHEST /TR "script-name"/F
Related
SCHTASKS /create /S $strComputer /tn "David\Start Gecko" /tr
"'C:\eQube-Tools\Batch and Registry Files\gecko.bat'" /sc once /sd
01/01/2099 /st 01:00 /u Boss /p *password* /RU SYSTEM
pause
SCHTASKS /run /S $strComputer /tn "David\Start Gecko"
So, I have a problem with running the batch file this creates, it says it's running on the task scheduler on the remote pc, but nothing happens. But the odd thing is: if I locally create a "basic task" it runs fine both remotely and running it by hand at that pc.
My question is there any way to have it know you want to create a "basic task" I've looked at the switches but can't find anything for /create, I also tried the /xml but this is something I plan to create, use then destroy so simpler the better.
** the reason I'm using SCHtasks is because I had a lot of issues with redirect errors trying to run it directly using powershell.
Specs
All win 7 WORKGROUP
All have matching Admin Accounts with matching password
Firewall set to allow remote sch tasks
Batch file is on remote pc
the batch file I'm trying to run
#echo off
c:
cd \eQube-Tools\Batch and Registry Files
start virtualhelpscreen.exe
:top
c:
cd \gecko
timeout 12 /nobreak
gecko.exe
cls
goto :top
SCHTASKS /create /S $strComputer /xml "filesavedtomainpc" /tn "David\Start Gecko"
one issue left is it not forcing full screen like it does when you run the batch file but that might be down to the program, for now the question I asked is answered.
I want to create a windows task which will run a batch file every day at 12.00am for only six months from the day the task is created. I'm using following command to create a task. I'm not sure how to set expiration date so that the task will stop executing after six months.
My command is:
schtasks /create /sc Daily /mo 10 /tn run /tr "C:\Users\Rashmi\test.bat" /st 00.00
Any help is appreciated.
get the help of Powershell to easily calculate the enddate (it's generaly possible with pure batch, but it's a nightmare):
for /f "delims=" %%a in ('powershell "(get-date).AddMonths(+6).ToString('MM/dd/yyyy')"') do set "enddate=%%a"
schtasks /create /sc Daily /mo 10 /tn run /tr "C:\Users\Rashmi\test.bat" /st 00.00 /ED %enddate%
See here for a pure batch solution and a solution using VBS instead of Powershell (but needs a temporary file).
You want a /ed parameter and to establish the value dynamically using the %date% value
See https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/schtasks#BKMK_create
Is it possible to move the start or run time of scheduled tasks in Windows server 2003 machine by 1 hour without hardcoding the time using /ST paramter of schtasks command? I also don't want to use Scheduled Tasks GUI because it is a lengthy process using it for many tasks.
For eg. if task A run at 8 AM and task B at 10 AM, I want to move them to 9 AM and 11 AM respectively. If it's not possible, please suggest better ways of doing it. Thanks in advance!
AFAIK schtasks does not provide a way to change the schedule relative to the existing schedule. You could query the current schedule from the task and then modify it accordingly:
setlocal EnableDelayedExpansion
for /f "tokens=5" %%t in (
'schtasks /query /tn foo /fo list ^| find /i "next run time:"'
) do (
if "%%t"="08:00:00" (
schtasks /change /tn foo /st 09:00
else if "%%t"="10:00:00" (
schtasks /change /tn foo /st 11:00
)
)
Can't be done with schtask.exe
You can't use the /st switch with the /change switch. You'd have to delete and create. But you would risk losing advanced options that you can't see with Schtask.exe. Basically you'll need to look at powershell instead to accomplish what you want.
I'm trying to create a batch file in order to run automatic scripts on several remote PCs.
My main machine should be able to connect to any remote PCs and set a local scheduled task.
The batch file uses these commands:
schtasks /delete <--- remove any previous version
/S \\10.1.2.3 <--- the remote PC's IP
/U theAdministrator <--- the username to access the PC
/P MyPassword <--- the password to access the PC
/TN MyTask <--- task name
/F <--- don't ask, just do it option
schtasks /create
/S \\10.1.2.3
/U theAdministrator
/P MyPassword
/RU theAdministrator <--- the username to execute the task
/RP MyPassword <--- the password to execute the task
/SC dayly /MO 1 <--- run every day
/TN MyTask
/TR C:\task.bat <--- the script to run on the remote PC
When I launch the first /delete command everything works, but the second returns a warning:
"task has been created but probably it will not run because it hasn't been possible to set the account information" (I'm sorry if this is not the exact error message but I have to translate it by myself)
I'm sure that username and password are correct because the /delete command is OK, and also /create one creates the task, even if it doesn't run.
Therefore the problem should be with /RU and /RP options...
Solution:
I wasn't able to execute the command itself without this error message, anyway I've reached my aim and found two different options:
The simplest way using the AT command:
AT \\10.1.2.3 12:00 C:\task.bat
It has no problem but needs to have specified an hour to run; this means if you want the task to be executed immediately you'll have to chatch %time% variable.
This option also doesn't allow to set an user to run the task (I've tested it as Administrator and the task was set to execute as NT AUTHORITY/SYSTEM)
The full featured way using PsTools:
Passing the schtasks /create command to PsExec
set command=schtasks /create /SC dayly /MO 1 /TN MyTask /TR C:\task.bat /RU theAdministrator /RP MyPassword
PsExec \\10.1.2.3 -u theAdministrator -p MyPassword %command%
NB.
The target IP, user and password to access the remote PC have to be set within PsExec command, therefore you don't need them on schtasks.
The script task.bat already exists on root C:\ of the target PC.
Are the PC's on a domain??
I've used schtasks on a domain before, and it works without the /ru and /rp. I just used /u and /p as the username and password of the machine that I was scheduling the task on.
Never tried it on standard workgroup/homegroup machines though.
You may also want to look at this, and make sure UAC is off on all remote machines, as thes could cause issues later.
Edit
I've just tried from one laptop to another (no domain involved).
These two lines work (in CMD, so should work through batch) for me
schtasks /delete /S \\xxx.xxx.xxx.xxx /U USERNAME /P PASSWORD /TN MyTask /F
schtasks /create /S \\xxx.xxx.xxx.xxx /U USERNAME /P PASSWORD /TN MyTask /SC once /st START_TIME /it /TR c:\test.bat
Things to note are;
- Obviously, replace the x's with the IP you need, and the USERNAME and PASSWORD with relevant data
- I used /sc once /st START_TIME, and not your /sc daily /mo 1, but that shouldn't make a difference
- I've added /it which (taken from CMD) "Enalbes the task to run interactively..." (in my experience, not using it has cause problems)
- The user on the laptop I was scheduling the task for does not exist on the laptop I ran schtasks from
- The user on the laptop I ran schtasks from does not exist on the laptop i was scheduling the task for (so users not existing on client/host does not matter)
I want to write a script that will stop a scheduled task on a remote computer, do some stuff, and then start the schedule task back up.
How can I do it?
Here's what I found.
stop:
schtasks /end /s <machine name> /tn <task name>
start:
schtasks /run /s <machine name> /tn <task name>
C:\>schtasks /?
SCHTASKS /parameter [arguments]
Description:
Enables an administrator to create, delete, query, change, run and
end scheduled tasks on a local or remote system. Replaces AT.exe.
Parameter List:
/Create Creates a new scheduled task.
/Delete Deletes the scheduled task(s).
/Query Displays all scheduled tasks.
/Change Changes the properties of scheduled task.
/Run Runs the scheduled task immediately.
/End Stops the currently running scheduled task.
/? Displays this help message.
Examples:
SCHTASKS
SCHTASKS /?
SCHTASKS /Run /?
SCHTASKS /End /?
SCHTASKS /Create /?
SCHTASKS /Delete /?
SCHTASKS /Query /?
SCHTASKS /Change /?
Note:
"schtasks" (see the other, accepted response) has replaced "at". However, "at" may be of use if the situation calls for compatibility with older versions of Windows that don't have schtasks.
Command-line help for "at":
C:\>at /?
The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.
AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] "command"
\\computername Specifies a remote computer. Commands are scheduled on the
local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled
command.
/delete Cancels a scheduled command. If id is omitted, all the
scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further
confirmation is desired.
time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user
who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week or
month. If date is omitted, the current day of the month
is assumed.
/next:date[,...] Runs the specified command on the next occurrence of the
day (for example, next Thursday). If date is omitted, the
current day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.
schtasks /change /disable /tn "Name Of Task" /s REMOTEMACHINENAME /u mydomain\administrator /p adminpassword
What about /disable, and /enable switch for a /change command?
schtasks.exe /change /s <machine name> /tn <task name> /disable
schtasks.exe /change /s <machine name> /tn <task name> /enable
Try this:
schtasks /change /ENABLE /tn "Auto Restart" /s mycomutername /u mycomputername\username/p mypassowrd