简体   繁体   English

更新/重新启动后Windows Server时间不正确

[英]Windows Server Time Incorrect After Updates/Reboot

We're running Windows Server 2012 R2. 我们正在运行Windows Server 2012 R2。 I've found that when the server installs updates and restarts (at 4am daily) it will restart in the incorrect time zone. 我发现服务器安装更新并重新启动时(每天凌晨4点),它将在不正确的时区重新启动。 Our time size is EST -5 (currently -4 with Daylight Savings), and the server defaults to UTC -0, which is 4 hours ahead of our time zone. 我们的时间大小为EST -5(当前为夏令时为-4),服务器默认为UTC -0,比我们的时区早4小时。

When we originally discovered the issue we found that the only workaround that actually worked was to use the task scheduler to run a sync command when the server restarted. 最初发现问题时,我们发现唯一有效的解决方法是在服务器重新启动时使用任务计划程序运行同步命令。 That task and command worked well until two weeks ago, around 6/15/2017, and since then it hasn't worked. 该任务和命令运行良好直到两周前(2017年6月15日左右),此后一直没有奏效。 I've reviewed the task/event logs and it claims to have run successfully, yet it hasn't. 我已经查看了任务/事件日志,它声称已成功运行,但尚未成功运行。

My only thought at this point is that there was something in the Windows update that rendered the sync code useless. 我现在唯一的想法是Windows更新中有一些东西使同步代码无用。 But I'm at a loss for what that could be. 但是我不知所措。 Does anyone have suggestions about how to identify the problem? 有人对如何确定问题有建议吗?

The sync code we are using is in a .bat file. 我们正在使用的同步代码位于.bat文件中。 The two Windows updates installed on the morning of 6/14, which I suspect could be the cause of the task no longer working, are: 我怀疑是6/14上午安装的两个Windows更新,它们可能是导致该任务不再起作用的原因,它们是:

2017-06 Security Monthly Quality Rollup for Windows Server 2012 R2 for x64-based Systems (KB4022726) 2017年6月适用于x64型系统Windows Server 2012 R2的每月安全性品质汇总套件(KB4022726)

Windows Malicious Software Removal Tool for Windows 8, 8.1, 10 and Windows Server 2012, 2012 R2, 2016 x64 Edition - June 2017 (KB890830) Windows 8、8.1、10和Windows Server 2012、2012 R2、2016 x64版的Windows恶意软件删除工具-2017年6月(KB890830)

REM *** Retry for up to 15 minutes (90 retries @ 10 seconds each)
set retryCount=0

:SyncStart
if %retryCount == 90 goto SyncEnd
set /A retryCount=retryCount + 1

REM *** Resync the system clock
net start w32time
w32tm /resync
if errorlevel 1 goto SyncDelay
if errorlevel 0 goto SyncEnd

:SyncDelay
REM *** If unsuccessful, delay 10 seconds, then retry
choice /n /t:y,10>nul
goto SyncStart

:SyncEnd

The batch file contains a syntax error in line: 批处理文件中包含以下语法错误:

if %retryCount == 90 goto SyncEnd

The value of an environment variables must be referenced with %VariableName% on using standard expansion and not just %VariableName like a FOR loop variable ( %I on cmd respectively %%I in a batch file) or a batch file argument ( %0 , %1 , ...), or with !VariableName! 的环境变量的值必须以引用%VariableName%上使用标准的扩展,而不仅仅是%VariableNameFOR循环变量( %I分别在CMD %%I在一个批处理文件)或批处理文件参数( %0%1 ,...)或带有!VariableName! on using delayed expansion which is not needed here. 使用延迟扩展,此处不需要。

The code could be also optimized: 代码也可以优化:

@echo off
REM *** Retry for up to 15 minutes (90 retries @ 10 seconds each)
set retryCount=0

:SyncStart
if %retryCount% == 90 goto :EOF
set /A retryCount+=1

REM *** Resync the system clock
%SystemRoot%\System32\net.exe start w32time
%SystemRoot%\System32\w32tm.exe /resync
if not errorlevel 1 goto :EOF

REM *** If unsuccessful, delay 10 seconds, then retry
%SystemRoot%\System32\timeout.exe 10 /nobreak
goto SyncStart

Well, the code can be optimized even more: 好了,代码可以进一步优化:

@echo off
REM *** Retry for up to 15 minutes (90 retries @ 10 seconds each)
set retryCount=0
%SystemRoot%\System32\net.exe start w32time
%SystemRoot%\System32\timeout.exe 5 /nobreak

:SyncTime
%SystemRoot%\System32\w32tm.exe /resync
if not errorlevel 1 goto :EOF

REM *** If unsuccessful, delay 10 seconds, then retry
set /A retryCount+=1
if not %retryCount% == 90 %SystemRoot%\System32\timeout.exe 10 /nobreak & goto SyncTime

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully. 为了了解所使用的命令及其工作方式,请打开命令提示符窗口,在其中执行以下命令,并非常仔细地阅读每个命令显示的所有帮助页面。

  • echo /?
  • goto /?
  • if /?
  • net /?
  • net start /?
  • rem /?
  • set /?
  • timeout /?
  • w32tm /?

And read the Microsoft support article Testing for a Specific Error Level in Batch Files . 并阅读Microsoft支持文章测试批处理文件中的特定错误级别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检测Windows重新启动是否是由Windows更新引起的 - Detect whether a Windows reboot was due to Windows updates 厨师重新启动资源会导致厨师运行超时,然后Windows服务器才能在更新和恢复配方后启动备份 - Chef reboot resource causes chef run to time out before Windows server is able to start back up after update and resume recipe 重启后如何检测Windows服务器是否可用? - How do I detect if a Windows server is available after a reboot? 在服务器重新启动时正常关闭 Windows 服务 - Graceful shutdown of windows service on server reboot 告诉Windows Server 2008从关机重启 - Tell reboot from shutdown on Windows Server 2008 重新启动后(Windows),厨师食谱是否可以继续? - Is there a way for a Chef recipe to continue after a reboot (Windows)? Windows 计划任务在重新启动后不起作用 - Windows Scheduled Task not working after a reboot 在 Windows 上重启后 Docker 不会自动启动 - Docker will not start automatically after reboot on Windows Windows 7路径直到重启后才由安装设置 - windows 7 path not set by install until after reboot 一个文件中所需的Windows更新和上次重启状态的已安装KB列表 - List of KB installed for Windows Updates and Last reboot Status required in one file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM