お世話になります。
タイムゾーンを設定するのに以下のようにして
みましたが、確かに東京に設定されているようですが、
現在指定されているタイム ゾーンは認識できません。
有効なタイム ゾーンを選択してください。
と日付と時刻の設定では表示されます。
なぜでしょうか?
よろしくお願いします。
const
SE_TIME_ZONE_NAME = 'SeTimeZonePrivilege';
SE_SYSTEMTIME_NAME = 'SeSystemtimePrivilege';
function NTSetPrivilege(sPrivilege: string; bEnabled: Boolean): Boolean;
var
hToken: THandle;
TokenPriv: TOKEN_PRIVILEGES;
PrevTokenPriv: TOKEN_PRIVILEGES;
ReturnLength: Cardinal;
begin
Result := True;
if not (Win32Platform = VER_PLATFORM_WIN32_NT) then Exit;
// obtain the processes token
if OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then
begin
try
// Get the locally unique identifier (LUID) .
if LookupPrivilegeValue(nil, PChar(sPrivilege),
TokenPriv.Privileges[0].Luid) then
begin
TokenPriv.PrivilegeCount := 1; // one privilege to set
case bEnabled of
True: TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
False: TokenPriv.Privileges[0].Attributes := 0;
end;
ReturnLength := 0; // replaces a var parameter
PrevTokenPriv := TokenPriv;
// enable or disable the privilege
AdjustTokenPrivileges(hToken, False, TokenPriv, SizeOf(PrevTokenPriv),
PrevTokenPriv, ReturnLength);
end;
finally
CloseHandle(hToken);
end;
end;
// test the return value of AdjustTokenPrivileges.
Result := GetLastError = ERROR_SUCCESS;
if not Result then
raise Exception.Create(SysErrorMessage(GetLastError));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
ZoneInfo: TTimeZoneInformation;
begin
if Win32MajorVersion >= 6 then
begin
Showmessage('NTSetPrivilege SE_TIME_ZONE_NAME enabled ? ' + BoolToStr(NTSetPrivilege(SE_TIME_ZONE_NAME, True), True));
end;
Showmessage('NTSetPrivilege SE_TIME_ZONE_NAME enabled ? ' + BoolToStr(NTSetPrivilege(SE_SYSTEMTIME_NAME, True), True));
with ZoneInfo do begin
Bias := -540;
//StandardName := '東京 (標準時)';
FillChar(StandardName,sizeof(StandardName),#0);
// can set any string
StringToWideChar('東京 (標準時)',StandardName,sizeof(StandardName));
StandardBias :=0;
DaylightName := '東京 (夏時間)';
FillChar(DaylightName,sizeof(DaylightName),#0);
StringToWideChar('東京 (夏時間)',DaylightName,sizeof(DaylightName));
DaylightBias := -60;
// DaylightDate
DaylightDate.wYear :=0;
DaylightDate.wMonth :=0;
DaylightDate.wDayOfWeek :=0;
DaylightDate.wDay :=0;
DaylightDate.wHour :=0;
DaylightDate.wMinute :=0;
DaylightDate.wSecond :=0;
DaylightDate.wMilliseconds :=0;
//StandardDate
StandardDate.wYear :=0;
StandardDate.wMonth :=0;
StandardDate.wDayOfWeek := 0;
StandardDate.wDay :=0;
StandardDate.wHour :=0;
StandardDate.wMinute :=0;
StandardDate.wSecond :=0;
Standarddate.wMilliseconds :=0;
end;
if not SetTimeZoneInformation(ZoneInfo) then
Showmessage('SetTimeZoneInformation Error Message: '+ SysErrorMessage(GetLastError))
else
ShowMessage('SetTimeZoneInformation : Success');
end;
なにをやりたいのかが書かれていないのでよくわかりませんが、こっちかもしれません。
SetDynamicTimeZoneInformation function (Windows)
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724932.aspx