Having problem with setting time zone from managed C++.

K

Ken Varn

I have a managed C++ method that I call from ASP.NET to set the time zone on
the local box. I call SetTimeZoneInformation, which does not return an
error, but the time zone remains unchanged. I have checked the web for any
information on this, but have not found any articles that relate to this
specific problem. Can anyone tell me what is wrong here?

Here is a sample snippet of the method:

Note that TimeZoneInfo is my own managed version of the native
TIME_ZONE_INFORMATION structure.

void SystemDateTime::SetTimeZoneInfo(TimeZoneInfo ZoneInfo)
{
TIME_ZONE_INFORMATION TZInfo = {0};
DWORD Result;
const wchar_t __pin *Name;

TZInfo.Bias = ZoneInfo.Bias;
TZInfo.StandardDate = DateTimeToSysTime(ZoneInfo.StandardDate);

Name = PtrToStringChars(ZoneInfo.StandardName);
wcscpy(TZInfo.StandardName,Name);
TZInfo.StandardBias = ZoneInfo.StandardBias;

Name = PtrToStringChars(ZoneInfo.DaylightName);
wcscpy(TZInfo.DaylightName,Name);

TZInfo.DaylightDate = DateTimeToSysTime(ZoneInfo.DaylightDate);
TZInfo.DaylightBias = ZoneInfo.DaylightBias;

if (!::SetTimeZoneInformation(&TZInfo))
{
int ErrorCode = GetLastError();
throw __gc new Win32Exception(ErrorCode,GetErrorMsg(ErrorCode));
}

SendMessageTimeout(HWND_BROADCAST,WM_SETTINGCHANGE,0,(LPARAM)
"intl",SMTO_BLOCK,15000,&Result);
}

SYSTEMTIME SystemDateTime::DateTimeToSysTime(DateTime DT)
{
SYSTEMTIME Ret = {0};
COleDateTime OleDT;

OleDT = DT.ToOADate();

OleDT.GetAsSystemTime(Ret);

return Ret;
}


--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
A

Abhijeet Dev

ASP.Net code runs under aspnet account, you probably would like to check
timezone setting for aspnet account, it should have changed. You can use
GetTimeZoneInformation in another ASP.Net application/service to check
if the timezone information is changed for aspnet account.
You can use impersonation if it is a system-wide setting or if there is
a user/group policy for this particular thing, add aspnet as one of the
accounts which can change this setting.
 
K

Ken Varn

I realize that the ASP.NET account has insufficient rights to set system
time. Hence, that is the reason that I am using impersonation to
impersonate an administrator account that I have reserved on the machine. I
would rather use this approach than to bump up the security rights of the
ASP.NET account. The problem is that I am still getting Access Denied
error.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top