views:

88

answers:

1

Hi All,

I have an MFC application that tries to change the system zone setting on the Windows Server 2008 R2. I am using the SetTimeZoneInformation() API which fails with the error code 1314 .i.e. “A required privilege is not held by the client.”. Please refer the sample code below:

TIME_ZONE_INFORMATION l_TimeZoneInfo;
DWORD l_dwRetVal = 0;
ZeroMemory(&l_TimeZoneInfo, sizeof(TIME_ZONE_INFORMATION));
l_TimeZoneInfo.Bias = -330;
l_TimeZoneInfo.StandardBias = 0;
l_TimeZoneInfo.StandardDate.wDay = 0;
l_TimeZoneInfo.StandardDate.wDayOfWeek = 0;
l_TimeZoneInfo.StandardDate.wHour = 0;
l_TimeZoneInfo.StandardDate.wMilliseconds = 0;
l_TimeZoneInfo.StandardDate.wMinute = 0;
l_TimeZoneInfo.StandardDate.wMonth = 0;
l_TimeZoneInfo.StandardDate.wSecond = 0;
l_TimeZoneInfo.StandardDate.wYear = 0;

CString l_csDaylightName = _T("India Daylight Time");
CString l_csStdName = _T("India Standard Time");

wcscpy(l_TimeZoneInfo.DaylightName,l_csDaylightName.GetBuffer(l_csDaylightName.GetLength()));
wcscpy(l_TimeZoneInfo.StandardName,l_csStdName.GetBuffer(l_csStdName.GetLength()));

::SetLastError(0);

if(0 == ::SetTimeZoneInformation(&l_TimeZoneInfo))
{
    l_dwRetVal = ::GetLastError();
    CString l_csErr = _T("");
    l_csErr.Format(_T("%d"),l_dwRetVal);
}

The MFC application has been developed using Visual Studio 2008 and is UAC aware i.e. the application has UAC enabled in its manifest file with the UAC execution level set to “HighestAvailable”. I have administrator privileges and when I run the application it still fails to change the system zone setting.

Thanks in Advance, Ganesh

A: 

You do not need to be running as an administrator to change the time zone. According to the documentation, you do need the SE_TIME_ZONE_NAME privilege, however. The document I linked to has a sample of how to enable the privilege, but it mostly involves calling AdjustTokenPrivileges on your process's access token.

Dean Harding
Thanks for your reply.Its seems it will solve the problem, but still verifying. Once confirmed will again get back to you.
Ganesh
Thanks again, the solution is perfectly helpful.
Ganesh

related questions