473,657 Members | 2,661 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 SetTimeZoneInfo rmation, 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_INFOR MATION structure.

void SystemDateTime: :SetTimeZoneInf o(TimeZoneInfo ZoneInfo)
{
TIME_ZONE_INFOR MATION TZInfo = {0};
DWORD Result;
const wchar_t __pin *Name;

TZInfo.Bias = ZoneInfo.Bias;
TZInfo.Standard Date = DateTimeToSysTi me(ZoneInfo.Sta ndardDate);

Name = PtrToStringChar s(ZoneInfo.Stan dardName);
wcscpy(TZInfo.S tandardName,Nam e);
TZInfo.Standard Bias = ZoneInfo.Standa rdBias;

Name = PtrToStringChar s(ZoneInfo.Dayl ightName);
wcscpy(TZInfo.D aylightName,Nam e);

TZInfo.Daylight Date = DateTimeToSysTi me(ZoneInfo.Day lightDate);
TZInfo.Daylight Bias = ZoneInfo.Daylig htBias;

if (!::SetTimeZone Information(&TZ Info))
{
int ErrorCode = GetLastError();
throw __gc new Win32Exception( ErrorCode,GetEr rorMsg(ErrorCod e));
}

SendMessageTime out(HWND_BROADC AST,WM_SETTINGC HANGE,0,(LPARAM )
"intl",SMTO_BLO CK,15000,&Resul t);
}

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

OleDT = DT.ToOADate();

OleDT.GetAsSyst emTime(Ret);

return Ret;
}
--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
Jan 25 '06 #1
2 3694
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
GetTimeZoneInfo rmation 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 SetTimeZoneInfo rmation, 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_INFOR MATION structure.

void SystemDateTime: :SetTimeZoneInf o(TimeZoneInfo ZoneInfo)
{
TIME_ZONE_INFOR MATION TZInfo = {0};
DWORD Result;
const wchar_t __pin *Name;

TZInfo.Bias = ZoneInfo.Bias;
TZInfo.Standard Date = DateTimeToSysTi me(ZoneInfo.Sta ndardDate);

Name = PtrToStringChar s(ZoneInfo.Stan dardName);
wcscpy(TZInfo.S tandardName,Nam e);
TZInfo.Standard Bias = ZoneInfo.Standa rdBias;

Name = PtrToStringChar s(ZoneInfo.Dayl ightName);
wcscpy(TZInfo.D aylightName,Nam e);

TZInfo.Daylight Date = DateTimeToSysTi me(ZoneInfo.Day lightDate);
TZInfo.Daylight Bias = ZoneInfo.Daylig htBias;

if (!::SetTimeZone Information(&TZ Info))
{
int ErrorCode = GetLastError();
throw __gc new Win32Exception( ErrorCode,GetEr rorMsg(ErrorCod e));
}

SendMessageTime out(HWND_BROADC AST,WM_SETTINGC HANGE,0,(LPARAM )
"intl",SMTO_BLO CK,15000,&Resul t);
}

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

OleDT = DT.ToOADate();

OleDT.GetAsSyst emTime(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****@abhijee t-dev.net> wrote in message
news:ug******** ******@TK2MSFTN GP15.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
GetTimeZoneInfo rmation 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 SetTimeZoneInfo rmation, 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_INFOR MATION structure.

void SystemDateTime: :SetTimeZoneInf o(TimeZoneInfo ZoneInfo)
{
TIME_ZONE_INFOR MATION TZInfo = {0};
DWORD Result;
const wchar_t __pin *Name;

TZInfo.Bias = ZoneInfo.Bias;
TZInfo.Standard Date = DateTimeToSysTi me(ZoneInfo.Sta ndardDate);

Name = PtrToStringChar s(ZoneInfo.Stan dardName);
wcscpy(TZInfo.S tandardName,Nam e);
TZInfo.Standard Bias = ZoneInfo.Standa rdBias;

Name = PtrToStringChar s(ZoneInfo.Dayl ightName);
wcscpy(TZInfo.D aylightName,Nam e);

TZInfo.Daylight Date = DateTimeToSysTi me(ZoneInfo.Day lightDate);
TZInfo.Daylight Bias = ZoneInfo.Daylig htBias;

if (!::SetTimeZone Information(&TZ Info))
{
int ErrorCode = GetLastError();
throw __gc new Win32Exception( ErrorCode,GetEr rorMsg(ErrorCod e));
}

SendMessageTime out(HWND_BROADC AST,WM_SETTINGC HANGE,0,(LPARAM )
"intl",SMTO_BLO CK,15000,&Resul t);
}

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

OleDT = DT.ToOADate();

OleDT.GetAsSyst emTime(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
11107
by: Neo | last post by:
Hi, Can anybody help me in writing a standard C++ program to set timezone to CST ? -Thanks, Venkat
3
35080
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
2283
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 moment) on the other computer. Both PCs are Windows XP Pro Service Pack 2. Both have their time zone set to GMT +0 (London). And in the Date & Time control panel applet, both show "GMT Standard Time" as the Current time zone. Both have the correct...
6
1400
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
14459
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 CURRENT_TIMESTAMP AT TIME ZONE 'UTC' and inserting into columns defined as TIMESTAMP WITHOUT TIME ZONE which appears to
2
14685
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 SetTimeZoneInformation, but it's not working correctly and I can't figure out why. I'm using Visual C# to write the application. The problem I'm having is that if I choose US Eastern Time (-5:00) Eastern Time (US & Canada) then the code below winds up setting...
2
2174
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 Windows issue, or a C++ issue, so I'm posting it both to a Windows group and to a C++ group. My OS is Windows 2000, and my compiler is Visual C++ 6.0. The warning I'm getting is this:
7
5503
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 Dim myzone As TimeZone = TimeZone.CurrentTimeZone If they change the Time zone whilst my application is running, a new call to Dim myzone As TimeZone = TimeZone.CurrentTimeZone returns the same time zone NOT the new one They have to restart my...
4
8411
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 per-connection basis, but how would I do that from PHP ? bill
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8612
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.