@ECHO OFF :: Keep all variables local SETLOCAL :: PMSOON Version SET PMSoonVer=1.01 :: Check command line parameters. :: Is a command specified? IF [%2]==[] GOTO Syntax :: No illegal switches used? ECHO.%* | FIND /I "/Every" >NUL IF NOT ERRORLEVEL 1 GOTO Syntax ECHO.%* | FIND /I "/Next" >NUL IF NOT ERRORLEVEL 1 GOTO Syntax :: Is the first parameter a valid system name? SET RemotePC=%1 IF "%RemotePC:~0,2%"=="\\" SET RemotePC=%RemotePC:~2% PING %RemotePC% 2>NUL | FIND "TTL=" >NUL IF ERRORLEVEL 1 GOTO Syntax :: Parse the remote command from the batch file's command line. :: Replace ("%*") by ('ECHO.%*') for NT 4 without SP. FOR /F "tokens=1* delims= " %%A IN ("%*") DO SET PMSoonCommand=%%B :: Check for time differences between local and remote system. FOR /F "tokens=6* delims= " %%A IN ('NET TIME \\%ComputerName% ^| FIND "Current"') DO ( SET LocalDate=%%A SET LocalTime=%%B ) FOR /F "tokens=6* delims= " %%A IN ('NET TIME \\%RemotePC% ^| FIND "Current"') DO ( SET RemoteDate=%%A SET RemoteTime=%%B ) :: Don't use this batch file 1 minute from midnight, as :: the following date comparison will most likely fail. IF NOT "%LocalDate%"=="%RemoteDate%" GOTO ErrDate SET LocalHH=%LocalTime:~0,2% SET Localmm=%LocalTime:~3,2% SET RemoteHH=%RemoteTime:~0,2% SET Remotemm=%RemoteTime:~3,2% :: If both date and time match, we're in luck. IF "%LocalTime%"=="%RemoteTime%" GOTO InSync :: Get an absolute value for the time difference by squaring it SET /A Diffmm = %Localmm% - %Remotemm% SET /A DiffmmSq = %Diffmm% * %Diffmm% :: If the hours match and the difference in minutes is 1 :: minute, consider the time of the systems synchronized. IF "%LocalHH%"=="%RemoteHH%" IF %DiffmmSq% LSS 2 GOTO InSync :: If the hours do not match, check if the :: time difference is still 1 minute only. SET /A DiffHH = %LocalHH% - %RemoteHH% SET /A DiffHHSq = %DiffHH% * %DiffHH% :: Check for 1 minute difference on the whole hour, as with 2:00 and 1:59. IF %DiffHHSq% LSS 2 IF %DiffmmSq% EQU 3481 GOTO InSync :: The systems' time difference seems to be too large for this batch file. GOTO ErrSync :: If you manage to get here, the systems seem to be synchronized close enough. :InSync :: Calculte time 2 minutes from now SET /A NearFuturemm = %Remotemm% + 2 SET /A NearFutureHH = %RemoteHH% IF %NearFuturemm% GTR 59 ( SET /A NearFuturemm = %NearFuturemm% - 60 SET /A NearFutureHH = %NearFutureHH% + 1 ) IF %NearFuturemm% GTR 59 IF %NearFutureHH% GTR 23 SET /A NearFutureHH = %NearFutureHH% - 24 IF %NearFuturemm% LSS 10 SET NearFuturemm=0%NearFuturemm% SET NearFuture=%NearFutureHH%:%NearFuturemm% :: Finaly, schedule the command AT \\%RemotePC% %NearFuture% %PMSoonCommand% :: And check the result AT \\%RemotePC% GOTO End :ErrHdr1 (ECHO.)1>&2 (ECHO PMSOON, Version %PMSoonVer% for Windows NT)1>&2 (ECHO Poor Man's replacement for the NT 4 Resource Kit's SOON command.)1>&2 GOTO:EOF :ErrHdr2 (ECHO.)1>&2 (ECHO Written by Rob van der Woude)1>&2 (ECHO http://www.robvanderwoude.com)1>&2 (ECHO.)1>&2 GOTO:EOF :ErrTimeDisp NET TIME \\%ComputerName% | FIND "Current" 1>&2 NET TIME \\%RemotePC% | FIND "Current" 1>&2 (ECHO.)1>&2 GOTO:EOF :ErrFtr1 (ECHO Command aborted.)1>&2 (ECHO.)1>&2 (ECHO Correct the problem ^(try NET TIME^) and try again.)1>&2 GOTO:EOF :ErrDate CALL :ErrHdr1 CALL :ErrHdr2 (ECHO ERROR: The date settings on the local and remote system do not match.)1>&2 (ECHO.)1>&2 CALL :ErrTimeDisp CALL :ErrFtr1 GOTO End :ErrSync CALL :ErrHdr1 CALL :ErrHdr2 (ECHO ERROR: The local and remote system's time settings differ more than 1 minute.)1>&2 (ECHO.)1>&2 CALL :ErrTimeDisp (ECHO Since PMSoon uses a 2 minute time interval, this is too risky.)1>&2 (ECHO Your command might be scheduled to run 24 hours later than intended.)1>&2 CALL :ErrFtr1 GOTO End :Syntax CALL :ErrHdr1 (ECHO Will schedule a command 2 minutes from now on a remote system.)1>&2 (ECHO Scheduler service must be active on the remote system.)1>&2 (ECHO You need to have administrative rights on the remote system.)1>&2 (ECHO Though PMSOON uses AT to schedule the command, AT's /EVERY and)1>&2 (ECHO /NEXT switches are NOT allowed.)1>&2 CALL :ErrHdr2 (ECHO Usage: PMSOON \\remote_pc command2BXecuted)1>&2 :End ENDLOCAL