Change Date and Time in non-admin mode

Peter Volz 1,295 Reputation points
2024-01-24T23:39:02.3866667+00:00

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.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,294 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,779 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 47,196 Reputation points
    2024-01-25T00:37:27.26+00:00

    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

    0 comments No comments

  2. 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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.