Change W32Time Registry Settings

(imported topic written by thesurg3on91)

Hello,

I’d like to create a Task that changes the registry based on IP address (different subnets go to different time server).

I’d like something like, If IP starts with 10.10 and ntpserver /= SERVERNAME from HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters and type /= ntp from key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters

then change the following 2 keys values

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters

Value

ntpserver (REG_SZ): SERVERNAME

type (REG_SZ): NTP

and then bounce/restart the w32time.exe service

How can I obtain this?

(imported comment written by BenKus)

Maybe this can help get you started:

The action will likely look like this:

parameter “SERVERNAME” = “{(if (exists addresses whose (it as string starts with “10.10”) of adapters of network) then “TimeServer1” else if (exists addresses whose (it as string starts with “10.11”) of adapters of network) then “TimeServer2” else “DefaultTimeServer”)}”

regset “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters” “ntpserver”="{parameter “SERVERNAME”}"
regset “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters” “type”="NTP"
waithidden cmd.exe /C net stop w32time
waithidden cmd.exe /C net start w32time

You will need to modify/expand the relevance that determines the servername based on the IP… Does that get you closer to what you were looking for?

Ben