6

I need to set windows clock in my Asp.net website (Written in C#)

I found a solution in stackoverflow at:

How do I set the Windows system clock to the correct local time using C#?

But when I use this I give exception:

A required privilege is not held by the client

My Application poll Identity is: LocalSystem

Community
  • 1
  • 1
Imran Sh
  • 1,623
  • 4
  • 27
  • 50
  • Are you trying to set the Windows clock on the server or the client's computer? – Karl Anderson Aug 05 '15 at 19:04
  • It's server (2008 r2 Enterprise). – Imran Sh Aug 06 '15 at 03:37
  • @ImranShams Have you granted the user "Run as a Service" privelige via the Local Security Policy? For some more info please refer [this](http://support.persits.com/show.asp?code=PS01032619) and [this](https://support.microsoft.com/en-us/kb/922737) – Krsna Kishore Sep 08 '16 at 04:14
  • let me check @Webruster – Imran Sh Sep 08 '16 at 11:44
  • @Webruster I can't set privelige, My Server OS is: 2008R2. Can u tell me how set it please? – Imran Sh Sep 11 '16 at 06:52
  • @ImranShams [Windows 7: Date and Time - Allow or Prevent Users and Groups from Changing](http://www.sevenforums.com/tutorials/113557-date-time-allow-prevent-users-groups-changing.html). Server 2008 R2 is the server equivalent of Windows 7. – Andrew Morton Oct 19 '16 at 17:36

2 Answers2

0

it is not a matter of "I need exact C# function for my problem", this is misguided. This is a security issue. Meddling with the clock is bad. Anyhow, to solve this you may try running the application pool under a user account that is member of the Administrators group and disable UAC.

You wont be able to change the clock on remote clients.

... also don't run an antivirus!

Oh, and disable clock synchronization of your system settings.

Ricardo C
  • 2,205
  • 20
  • 24
  • To the down-voter: He is trying to set the computer's clock from code on his web app, and not just to display the time in a page. – Ricardo C Sep 29 '16 at 22:33
-1
<

div class="dp-highlighter"><div class="bar"><div class="tools">view plaincopy to clipboardprint?</div><div class="columns"><div>·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150</div></div></div>

    protected void Page_Load(object sender, EventArgs e)  
    {  
            lblTime.Text = DateTime.Now.ToString("hh:mm:ss");  

        }  
        protected void TimerTime_Tick(object sender, EventArgs e)  
        {  
            lblTime.Text = DateTime.Now.ToString("hh:mm:ss");  
        }  

    <asp:ScriptManager ID="ScriptManager1" runat="server">  
            </asp:ScriptManager>  
            <asp:Timer ID="TimerTime" runat="server" Interval="1000">  
            </asp:Timer>  
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
            <ContentTemplate>  
            <asp:Label ID="lblDateToday" runat="server"></asp:Label>  
                    <asp:Label ID="lblTime" runat="server"></asp:Label>  
                </ContentTemplate>  
                <Triggers>  
                    <asp:AsyncPostBackTrigger ControlID="TimerTime" EventName="Tick" />  
                </Triggers>  
            </asp:UpdatePanel>  
            </div>  
            <br />  

</div>

protected void Page_Load(object sender, EventArgs e)
{
        lblTime.Text = DateTime.Now.ToString("hh:mm:ss");


    }
    protected void TimerTime_Tick(object sender, EventArgs e)
    {
        lblTime.Text = DateTime.Now.ToString("hh:mm:ss");
    }


<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:Timer ID="TimerTime" runat="server" Interval="1000">
        </asp:Timer>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <asp:Label ID="lblDateToday" runat="server"></asp:Label>
                <asp:Label ID="lblTime" runat="server"></asp:Label>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="TimerTime" EventName="Tick" />
            </Triggers>
        </asp:UpdatePanel>
        </div>
        <br />

check out http://forums.asp.net/t/1528616.aspx?How+to+diplay+real+time+timing+clock+on+asp+net+web+page https://msdn.microsoft.com/en-us/library/ms172517(v=vs.90).aspx

youngdero
  • 382
  • 2
  • 16