
|


|
|
|
soon.bat for Windows
Previous versions of the Windows Resource Kit shipped with a utility called "soon.exe". This useful little tool used the Windows scheduler service to make a deferred command happen "real soon now" -- great when you need to launch something (like cmd.exe or regedit) in the local system security context. Unfortunately, soon.exe does not ship with the current resource kit. The attached batch file provides basically the same functionality.

Contributed by: Unknown User anonymous2
[04/16/04 | Discuss (2) | Link to this hack] |
@if (%_echo%)==() echo off
setlocal
if (%1)==() goto Usage
set _command=%*
for /F "tokens=1,2,3 delims=:." %%i in ("%time%") do call :DoIt %%i %%j %%k
goto :EOF
:DoIt
rem %1 = hour
rem %2 = minute
rem %3 = second
set _hour=%1
if (%_hour:~0,1%)==(0) set _hour=%_hour:~1%
set _minute=%2
if (%_minute:~0,1%)==(0) set _minute=%_minute:~1%
set /a _minute+=1
if %3 GEQ 55 set /a _minute+=1
if %_minute% LSS 60 goto :DontFixMinute
set /a _minute-=60
set /a _hour+=1
:DontFixMinute
if %_hour% LSS 24 goto :DontFixHour
set /a _hour-=24
:DontFixHour
rem schedule it
at %_hour%:%_minute% /interactive %_command%
rem print the current schedule list
at
rem print the current time
time < nul | findstr -i current
goto :EOF
:Usage
echo use: soon command [parameters]
goto :EOF
Showing messages 1 through 2 of 2.
-
soon.cmd/soon.bat using schtasks.exe
2005-07-22 16:40:50
JacG
[View]
-
more great stuff!
2004-11-30 12:11:46
dcorrell
[View]
|
Showing messages 1 through 2 of 2.
|
|
O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website:
| Customer Service:
| Book issues:
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
|
|
|
Great lil' piece of code!
Here's a slightly modified version that uses schtasks.exe instead of at.exe. The advantage of schtasks.exe is that you can set a user name and password. For example, I am going to use this to make a remote system backup its system state (see example below) and that's simply impossible with at.exe because at.exe runs without the needed access rights.
@if (%_echo%)==() echo off
setlocal
if (%1)==() goto Usage
set _command=%1
if not (%2)==() set _command=%_command% /s %2
if not (%3)==() set _command=%_command% /u %3
if not (%4)==() set _command=%_command% /p %4
for /F "tokens=1,2,3 delims=:." %%i in ("%time%") do call :DoIt %%i %%j %%k
goto :EOF
:DoIt
rem %1 = hour
rem %2 = minute
rem %3 = second
set _hour=%1
if (%_hour:~0,1%)==(0) set _hour=%_hour:~1%
set _minute=%2
if (%_minute:~0,1%)==(0) set _minute=%_minute:~1%
set /a _minute+=1
if %3 GEQ 55 set /a _minute+=1
if %_minute% LSS 60 goto :DontFixMinute
set /a _minute-=60
set /a _hour+=1
:DontFixMinute
if %_hour% LSS 24 goto :DontFixHour
set /a _hour-=24
:DontFixHour
rem schedule it
schtasks /create /st %_hour%:%_minute% /sc once /z /tn "Scheduled by %username% on %computername% with %0" /it /tr %_command%
rem print the current time
time < nul | findstr -i current
goto :EOF
:Usage
echo use: %0 "command [parameters]" [server [user [password]]]
goto :EOF
Example
soon "ntbackup backup systemstate /f \\backupserver\backup\state.bkf" remoteserver administrator secret