【问题标题】:Unable to change the system zone setting on Windows Server 2008 R2无法更改 Windows Server 2008 R2 上的系统区域设置
【发布时间】:2010-06-09 04:55:08
【问题描述】:

我有一个 MFC 应用程序,它试图更改 Windows Server 2008 R2 上的系统区域设置。我正在使用失败的 SetTimeZoneInformation() API,错误代码为 1314。即“客户不拥有所需的特权。”。请参考下面的示例代码:

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,即应用程序在其清单文件中启用了 UAC,并且 UAC 执行级别设置为“HighestAvailable”。我有管理员权限,当我运行应用程序时,它仍然无法更改系统区域设置。

提前致谢, 象头神

【问题讨论】:

    标签: windows-server-2008


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复。它似乎会解决问题,但仍在验证。确认后将再次回复您。
    • 再次感谢,这个解决方案非常有用。
    猜你喜欢
    • 2015-10-07
    • 2011-06-15
    • 1970-01-01
    • 2011-12-18
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多