2010-06-09 88 views
0

我有一个MFC应用程序尝试更改Windows Server 2008 R2上的系统区域设置。我使用的SetTimeZoneInformation()API失败,错误代码为1314.i.e。 “所需的特权不是由客户持有的。”请参考下面的代码示例:无法更改Windows Server 2008 R2上的系统区域设置

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); 
} 

MFC应用程序已经使用Visual Studio 2008开发的,支持UAC即应用程序与设置为“HighestAvailable”的UAC级别执行其清单文件中启用UAC。我有管理员权限,当我运行应用程序时,仍然无法更改系统区域设置。

由于事先 Ganesh神

回答

0

你并不需要运行以管理员身份更改时区。 According to the documentation,你需要SE_TIME_ZONE_NAME特权,但是。我链接到的文档有一个如何启用该特权的示例,但它主要涉及在进程的访问令牌上调用AdjustTokenPrivileges

+0

感谢您的回复。 它似乎会解决问题,但仍然验证。一旦确认将再次回到你身边。 – Ganesh 2010-06-11 06:09:07

+0

再次感谢,该解决方案非常有帮助。 – Ganesh 2010-06-17 14:54:05

相关问题