Click here to Skip to main content
15,884,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to change system date through my c# application,
as there is problem with cmos battery.
so how could i get current date ?
?
and not to change cmos battery...
Posted

1 solution

IF you can't trust the CMOS battery, then you need to get the time from the internet. There are a number of internet time servers which you can use: Google can help you, just look for NIST or NTP servers.

Setting the system clock though is a privileged operation - which means you need admin permissions to do it. The code is simple: http://msdn.microsoft.com/en-us/library/ms172517(v=vs.90).aspx[^] - but it may be more of a PITA that you want.

Me? I'd change the battery - they aren't expensive and old leaky batteries can do serious damage to the PCB!
 
Share this answer
 
Comments
Madhuri Gamane 18-Sep-14 3:14am    
actually the application is deployed,
.
client don't have internet connection, and also not ready to change CMOS cell.. :-(
OriginalGriff 18-Sep-14 3:32am    
Then:
1) He's stuffed. If he can;t access any clocks (internal or external) then he will have to continue to reset the time manually.
2) It's his problem. We - as developers - do not have responsibility for his broken hardware. Would he expect your software to "work round" a broken monitor or keyboard?
Bernhard Hiller 18-Sep-14 9:19am    
If they have a domain, the domain controller can be setup as a time server, and the client gets the "correct" time from that server during Windows startup.
OriginalGriff 18-Sep-14 9:34am    
Replacing the battery is a much better idea! :laugh:
Bernhard Hiller 18-Sep-14 10:57am    
True. But such are the customers we are used too, aren't they?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900