My task is to set the machine's clock to UTC using a PC connected by modbus. Hundreds of these will be deployed across the country and beyond. Requiring manual intervention by the end user is not an option. So, not at all knowing what I'm doing, I've been slogging around the swamp for a while, and I think I stumbled on the answer. I ended up here: https://learn.microsoft.com/en-us/windows/win32/wmisdk/swbemdatetime Based on that, I came up with this, which appears to work: Set dateTime = CreateObject("WbemScripting.SWbemDateTime")...
Or maybe not. When I try to run this it doesn't update. If I comment out the for loop it updates, but it doesn't have the UTC offset. I'm also not sure I see how to get the bias for the local time zone. dim d dim offset offset = 0 Dim wmi : Set wmi = GetObject("winmgmts:root\cimv2") Set timeZones = wmi.ExecQuery("SELECT Bias, Caption FROM Win32_TimeZone") For Each tz In timeZones tz.Bias = -300 tz.Caption = (UTC-05:00) Eastern Time (US & Canada) Next d = DateAdd("n", offset, Now()) 'd = Now() SetRegisterValue...
Oops! I should have read your post more carefully. The stack overflow link shows how to do it. Thanks!
Hi Doug, My customer is saying they want the time in UTC. I've seen some posts showing how to read the registry time offset, but I can't get them to work. Here's what one says to do: Dim var_offset Dim WshShell set WshShell = WScript.CreateObject("WScript.Shell") var_offset = WshShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias") d = DateAdd("n", var_offset, Now()) But as soon as I add the 'set' line it stops working. I guess you aren't running wscript interpreter?...
Hi Doug, Thanks for the fast response. I was going to post a message this morning that I had figured it out, but you beat me to it. I found the help page, and that told me I needed a VB script and some of the syntax I needed. Then googling 'vb script date' gave me the functions I needed. I ended up with this: dim d d = Now() SetRegisterValue 3, 1, DatePart("s", d) SetRegisterValue 3, 2, DatePart("n", d) SetRegisterValue 3, 3, DatePart("h", d) SetRegisterValue 3, 4, DatePart("w", d) SetRegisterValue...
How do you write scripts? I have a customer with a Modbus client with no user I/O and they want to set the real-time clock. They suggested Open ModSim, and I learned enough javascript to write a script that reads the PC clock and writes time into holding registers. But I can't get it to respond to my requests. I downloaded ModRSsim2 and it replies to the request, but I need to get the time values from the PC's RTC into the registers. Thanks in advance.