应用程序加载时自动将系统时间更新为互联网时间... [英] Auto update my system time to internet time as application loads...

查看:83
本文介绍了应用程序加载时自动将系统时间更新为互联网时间...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,每次我的应用程序Windows登录表单加载时,我都需要一个代码来更新系统时间到互联网时间。如果这是不可能的,我想要一种方法,如果它关闭,以编程方式打开自动更新日期时间窗口功能。



我试过的:



我在互联网上搜索了代码,但未找到符合我要求的任何内容。请帮帮我们......

解决方案

请看这里: MSDN:如何:获取或设置系统时间 [ ^ ]


设置时间需要提升权限。



按照OriginalGriff的建议使用 SetSystemTime 时,您的应用必须拥有 SE_SYSTEMTIME_NAME 未设置为非管理帐户的权限。



更改自动时间更新配置等其他方法需要管理权限。一个示例是用于配置时间服务的命令行工具: Windows时间服务工具和设置:Windows时间服务 [ ^ ]。



所以从安全的角度来看,最好的选择是使用 SetSystemTime 并仅为您的应用程序提供 SE_SYSTEMTIME_NAME 权限而非完全管理员权限。



均匀更好的选择是让您的应用程序通过与净时间服务的数据进行比较来检查实际时间是否正确。您可以通知用户是否要求设置时间差异太大(或者只启用Windows时间服务)。


您好Akinloluwa。



有这种问题的解决方案这里是解决方案的链接。



希望它有所帮助。欢呼声。

Hi Guys, I need a code to update system time to internet time every time my application windows login form loads. If this is not possible, I'll like a way to programmatically turn on the auto update datetime windows feature if its turned off.

What I have tried:

I have searched the internet for codes but not found anything specific to my requirements. Help guys, please...

解决方案

See here: MSDN: How to: Get or Set the System Time[^]


Setting the time requires elevated privileges.

When using SetSystemTime as suggested by OriginalGriff, your application must have the SE_SYSTEMTIME_NAME privilege which is not set for non-administrative accounts.

Other methods like changing the automatic time update configuration require administrative privileges. An example is the command line tool to configure the time service: Windows Time Service Tools and Settings: Windows Time Service[^].

So from the security point of view, the best option is to use SetSystemTime and give your application only the SE_SYSTEMTIME_NAME privilege rather full adminstrative privileges.

An even better option would be letting your application check if the actual time is correct by comparing with data from a net time service. You can than inform the user if the difference is too large asking for setting the time (or just enable the Windows time service).


Hi Akinloluwa.

There is a solution to this type of a problem here is a link to the solution.

Hope it helps. cheers.


这篇关于应用程序加载时自动将系统时间更新为互联网时间...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆