Joandre Tait
Joandre Tait

Reputation: 23

Setting system time windows 10 without elevation

So I've read a few questions regarding setting the system time on Windows 10 and the requirement to either have the process elevated or disabling the UAC on the machine. The issue I face is that I am not able to do either.

So to give clarity, I'm have a WinForms application that has to run as a standard user as the machine is an unattended terminal that automatically logs in and executes the application using the Startup folder to execute the application. Once the application is open it performs some operations of which one is retrieving a DateTime value from the server (a RESTful API) and needs to persist this value to the system. I know that this is sort of "reinventing the wheel", but this is what the customer wants as they don't wish to use SNTP and disabling the UAC is out of the question as it creates security holes and the network/system admin will not allow this to be done.

So now I've gone ahead and updated the Group Policy for "Computer Configuration > Windows Settings > Security Settings > Local Policies > User Rights Assignment > Change the system time" to include "Everyone", yet I'm still receiving an Error 1314 when I call public static extern bool SetSystemTime(ref SYSTEMTIME st) from the imported DLL [DllImport("kernel32.dll", SetLastError = true)].

An idea was to set the system time using a Windows Service that is installed with admin privileges that would be able to update the system time no problem, yet the OnCustomCommand only allows for the passing of a single integer value per command type and won't allow for extra parameters without writing some inter-process communication or pipeline for changing the system time to the provided value.

Am I missing something or is there no simple, easy, clean and safe way to perform this action or would it be best that the client just put aside preferences and use SNTP?

Thank you in advance.

Upvotes: 0

Views: 362

Answers (1)

Joandre Tait
Joandre Tait

Reputation: 23

Thanks to @ADyson for the comment:

"P.S. If you really have to do this, you could pass data to the background service simply by writing it to a file, and telling the service to look in that file for the data. Or...just don't use a winforms app at all. Basically you could write your service to be something that's installed on every machine that needs it, runs in the background constantly, gets the data from the API on a regular basis and updates the system time. So basically an alternative to SNTP (albeit probably lower-quality overall, but does a similar job)."

This will literally be the best solution to easily and quickly implement the required functionality. I know it is not "the right way", but for the requirements and constraints, it is "the best way".

Upvotes: 1

Related Questions