1. 程式人生 > >【轉】修改系統時間

【轉】修改系統時間

我的客戶遇到系統時間不對,自己又不會改,於是想到利用服務端時間來修改本地的系統時間。

第一步,把下面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