Changing the system time requires a privilege that is not ordinarily present in the token of a non-administrator account. Although I don't recommend doing this it is possible to edit the local security policy user rights assignment to change this. There is a lengthy discussion of this issue at https://learn.microsoft.com/en-us/answers/questions/1498058/setsystemtime()-setlocaltime()-failed-error-privil
Change Date and Time in non-admin mode
Hello gurus, Never needed to do so inside a .net app, but now that I need and found it requires admin privilege, I'm surprised, didn't know if changing the date is security related. Anyway, is there any way to do so in non-admin mode in vb.net or C#? I found something here: https://stackoverflow.com/questions/26900950/how-to-change-system-date-and-time-with-vb-net-on-windows-7 That mentioned SetLocalTime function, but seems not in vb/c#, anyone knows if it can be used to do the task in the non-admin mode? Thanks.
2 answers
Sort by: Most helpful
-
-
Jiachen Li-MSFT 33,451 Reputation points Microsoft Vendor
2024-01-25T07:18:55.33+00:00 Hi @Peter Volz ,
If you want to change Date and Time in non-admin mode, you need to Assigning Privileges to an Account so that the account which is running this application could change Date and Time.
Assign privileges to the account by using the Local Security Policy Microsoft Management Console (MMC) snap-in (Secpol.msc).
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.