Missing rights to set system time from script RRS feed

  • Question

  • I am making a graphical user interface (GUI) in the Siemens application WinCC.

    Here I have a piece of code that allows me to synchronize the GUI-PC system time with the controller (PLC) running the physical machine.

    It Works in Windows7 - but I run into access rights in Windows10. In Win 7 I have to set UAC to the lowest level - and I have done the same on Win 10 - but it still fails.

    The code is (sample code where I just adjust with 5 minutes):

    Sub TestSub1
      Dim WMIService
      Dim ObjPrivileges
      Dim ItemPriv
      Dim OSlist
      Dim DTime
      Dim OS
      Dim ErrorCode

     Set WMIService = GetObject("winmgmts:{impersonationLevel=impersonate, (SystemTime)}!\\.\root\cimv2")
      Set ObjPrivileges = WMIService.security_.Privileges
      For Each ItemPriv In ObjPrivileges
       HMIRuntime.Trace "   " & itempriv.identifier & "  " & & " " & itempriv.displayname & "   Enabled=" & itempriv.isenabled & vbCrlf

     Set OSlist = WMIService.instancesof("Win32_operatingSystem")
      Set DTime = CreateObject("WbemScripting.SWbemDateTime")
      For Each OS In OSlist
       DTime.Value = OS.LocalDateTime
       DTime.Minutes = DTime.Minutes + 5
       ErrorCode = OS.setdatetime(DTime.Value)
       If Errorcode = 0 Then
        HMIRuntime.Trace "New time set to: " & dtime.Value & vbCrlf
        HMIRuntime.Trace "Cannot set system time - ErrorCode: " & ErrorCode & vbCrlf
       End If

    End Sub

    It fails in the statement

    ErrorCode = OS.setdatetime(DTime.Value)

    Any suggestions on how to get the appropriate user right?

    Thursday, April 19, 2018 11:58 AM

All replies

  • Hi,

    You could run a program as Administrator, and to do that, you must supply the password for Administrator. There is not a direct equivalent of sudo in Windows. There does not exist a good way to embed Administrator credentials in the script.

    Anyway, you don't give permissions or access rights to programs. You give permissions to users, who execute programs. These programs execute in the security context of that user. The programs inherit their security privileges from the user who executed them.

    Also check the user rights assignment in group policy.

    Hope it will be helpful to you

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact

    Friday, April 20, 2018 3:17 AM
  • Hi Carl,

    thank you for your reply.

    The GUI is running on an account with administrator rights.

    And the "Change the system time" in "User Rights Assignment" follows the Policy: "LOCAL SERVICE,Administrators"

    So I would really think that the program has the sufficient rights - but it does not Work.

    I even list what I believe is the privilege for setting the time:

      11  SeSystemtimePrivilege Change the system time   Enabled=True

    So it really looks like I have the correct right/privilege - but somehow it's not right.

    Any other way of listing the actual rights during runtime?


    Friday, April 20, 2018 1:26 PM
  • I got it working by adding the specific user that is active on the GUI PC to the Policy for "Change the system time".
    Monday, April 23, 2018 2:44 PM
  • Hi Jake,

    Thank you for your update and sorry for the late reply.

    Yes, you could add the user account to the group in this policy.

    Glad to hear that you have solved it and thank you for sharing it here, it will be helpful to other community members who have same questions.


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact

    Tuesday, April 24, 2018 1:54 AM
  • Now - the solution described above works on a VMware with Windows10.

    I am however now doing an installation on a real physical PC - and here it does not work...

    I have added the active user to the Policy for "Change the system time". But here it does not work (after reboot to make the change take effect).

    I even tried adding all possible objects - by simply selecting ALL I could find in the list. But no luck either.

    Any suggestions?

    Wednesday, May 23, 2018 1:34 PM