473,505 Members | 13,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
2 3675
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11101
by: Neo | last post by:
Hi, Can anybody help me in writing a standard C++ program to set timezone to CST ? -Thanks, Venkat
3
35043
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
5
2277
by: Swansea University Psychology | last post by:
Hi all, I have a utility that uses the C library function strftime() to return the time zone name, but it returns "GMT Standard Time" on one computer, and "BST" (which it should be at the...
6
1391
by: ABC | last post by:
Follow my project, the connection database will not use Trused Connection from web server to database server. How to set DAAB's connection string with No Credentials Access?
13
14440
by: Stuart Bishop | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi. I'm trying to determine the best way of saying 'The current time in UTC with no time zone information'. I'm currently using...
2
14672
by: Mike | last post by:
I'm writing an application for Windows XP Embedded. This application requires that the user be able to change the time zone from within the application. I'm trying to do this using...
2
2164
by: Robbie Hatley | last post by:
I'm getting a strange warning at work when I compile any file in our product that contains a deque of a particular struct. I don't understand this warning, so I'm not sure if this is a Microsoft...
7
5497
by: Steve | last post by:
Hi All I have a windows application written in VB.net 2005 The users have to select a State of Australia, which I use to check they have the correct windows time zone selected in control panel...
4
8399
by: bill | last post by:
I am using the MySQL date and time functions and they save a lot of my time. But the server is located in a time zone 2 hours away. I read in the SQL docs how to set the timezone on a...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.