
正文
修改系统时间(取得服务器时间,使用SetLocalTime API函数,需要UAC权限)
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
我的客户遇到系统时间不对,自己又不会改,于是想到利用服务端时间来修改本地的系统时间。
第一步,把下面xml存成uac.xml文件备用。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false">
</requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="x86"
publicKeyToken="6595b64144ccf1df"
language="*">
</assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>

接下来,看代码:

procedure TForm12.SyncLocalDateTime;//同步本地时间
var
systemtime: Tsystemtime;
DateTime: TDateTime;
begin
SetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SSHORTDATE, 'yyyy-MM-dd');
DateTime := GetServerDateTime;//取服务器日期
System.Sysutils.DateTimeToSystemTime(DateTime, systemtime);
SetLocalTime(systemtime);
end;

需要引用单元:Winapi.Windows
编译时,使用刚才做的uac.xml文件:

在Delphi 10.3+win10测试通过。
原文地址:https://www.cnblogs.com/stroll/p/6913769.html
https://www.cnblogs.com/kinglandsoft/p/10087576.html







