﻿# 網域主控站(DC)如何正確設定 Windows 時間服務 (w32tm)

在我之前的[校時文章](/post/2009/06/08/How-to-adjust-Time-using-Windows-Time-Service)中已經提及很多關於 Windows 自動校時的方式，但當時對**網域主控站**的校時方式的說明有點問題，我已經修改該篇文章，並以這邊文章專講「網域主控站」的校時設定。

如果之前已經參照改文章修改機碼設定，想回復 Windows Time Service 的預設值可參考以下指令：

```
net stop w32time
w32tm /unregister
w32tm /register
net start w32time
```

以下指令我都將以[國家時間與頻率標準實驗室](https://www.stdtime.gov.tw/)所提供的 [NTP 伺服器清單](https://www.stdtime.gov.tw/chinese/Bulletin/NTP%20promo.txt)作為範例進行設定。

### 在**網域主控站**(PDC)手動設定校時伺服器

    以下指令應該才是在網域主控站「**正宗**」的校時設定指令，跟**單機**或**網域成員電腦**的設定不一樣。

> w32tm /config /manualpeerlist:"time.stdtime.gov.tw clock.stdtime.gov.tw tick.stdtime.gov.tw watch.stdtime.gov.tw" /syncfromflags:manual /reliable:yes /update

### 顯示本地時間與目的時間的時間差

> w32tm /stripchart /computer:**tick.stdtime.gov.tw** /samples:30 /dataonly

以上這行指令就可以看出一些 Windows 時間服務的執行細節，像我故意修改我本機的時間調慢一分鐘，然後執行上述指令時，你可以看出**本地的時間**其實是慢慢的跟**目的電腦(tick.stdtime.gov.tw)**趨近，如下：

```
C:\>w32tm /stripchart /computer:tick.stdtime.gov.tw /samples:30 /dataonly
Tracking tick.stdtime.gov.tw [220.130.158.71].
Collecting 30 samples.
The current time is 2009/6/16 下午 10:39:13 (local time).
22:39:13, +62.1259256s
22:39:15, +62.0827790s
22:39:17, +62.0437263s
22:39:19, +62.0123067s
22:39:21, +61.9782861s
22:39:23, +61.9456177s
22:39:25, +61.9136171s
.......
```

這也是使用 Windows 時間服務校時的好處，他不會像使用 [NTPClock.exe](https://www.stdtime.gov.tw/chinese/EXE/NTPClock.exe) 工具很暴力的將你的時間直接調回正確的時間，進而影響原本系統的運作或造成事件記錄的時間錯亂，有時後大幅度的調整時間會讓應用程式直接掛點(Crash)，你可以試試開啟 Visual Studio 2008 之後手動調整時間，他真的立即掛給你看，然後你可以看看事件檢視器中的事件寫些什麼。

所以只要是「伺服器層級」的電腦，建議都使用 Windows 內建的校時服務進行校時工作！

**2011-08-10 補充**

下圖是透過 Windows Server 2008 R2 的 BPA (Best Practics Analyzer) 提醒的訊息，供參考：

![](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/01d7f1f82a3a390bb96c-PDC_w32tm.png)

**相關連結**

-   [國家時間與頻率標準實驗室](https://www.stdtime.gov.tw/)
-   [Administering the Windows Time Service](http://technet.microsoft.com/en-us/library/cc782712\(WS.10\).aspx)
-   [Configuring a time source for the forest](http://technet.microsoft.com/en-us/library/cc784800.aspx)
-   [Configure the Windows Time service on the PDC emulator](http://technet.microsoft.com/en-us/library/cc786897\(WS.10\).aspx)
-   [Windows Time Service Tools and Settings](http://go.microsoft.com/fwlink/?LinkId=42984)
-   [How to configure an authoritative time server in Windows Server](http://support.microsoft.com/kb/816042/en-us)
