1

I need to change server time from asp.net page. Is it possible?

Andy
  • 766
  • 1
  • 6
  • 16

3 Answers3

4

Possible or not, it's a bad idea. And the only way I can think of allowing this is if the user account the app pool is executing under has some serious access rights to the machine; which is also a very bad idea.

Servers should be sync'd with a time server. This is normally controlled at the OS level.

All sorts of funky things can happen once one server in a mix gets out of an acceptable date range.

Which leads us to the question: Why?


UPDATE

You could pinvoke SetSystemTime. This will require the user the app pool is running under to have the SeSystemTimePrivilege. More information and an example of pinvoking here: http://bytes.com/topic/c-sharp/answers/274594-how-set-system-date-c

Again, this is a Bad Idea(tm).

NotMe
  • 87,343
  • 27
  • 171
  • 245
0

I know this is not what you asked and does not change the server time, only changes the time from the perspective of the asp.net page. If the time difference is a constant then this code might be your friend!

This example adds 1 hour from now...

var today = DateTime.Now; 
var duration = new TimeSpan(1, 0, 0); 
var answer = today.Add(duration);
Rippo
  • 22,117
  • 14
  • 78
  • 117
0

Here's a thread explaining how to change systemtime

I can't get SetSystemTime to work in Windows Vista using C# with Interop (P/Invoke)

You will need elevation to get this to work.

Community
  • 1
  • 1
Ralf de Kleine
  • 11,464
  • 5
  • 45
  • 87