I need to change server time from asp.net page. Is it possible?
3 Answers
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).

- 87,343
- 27
- 171
- 245
-
1+1, Plus, you will need elevated privileges for the asp.net apppool account. Bad idea if I've ever seen one. – Klaus Byskov Pedersen Dec 20 '10 at 19:27
-
Kerberos implementations will fail if times get out of sync. This is but one example of a "funky thing" – Conrad Frix Dec 20 '10 at 19:28
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);

- 22,117
- 14
- 78
- 117
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.

- 1
- 1

- 11,464
- 5
- 45
- 87