By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,360 Members | 1,805 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,360 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
-----------------------------------
Jan 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

--
Abhijeet Dev

Ken Varn wrote:
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;
}

Jan 27 '06 #2

P: n/a
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
-----------------------------------
"Abhijeet Dev" <ms****@abhijeet-dev.net> wrote in message
news:ug**************@TK2MSFTNGP15.phx.gbl...
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.

--
Abhijeet Dev

Ken Varn wrote:
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;
}

Jan 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.