p/invoke GetSystemTime() method is giving wrong output - compact-framework

I used p/invoke GetSystemTime() method in my application to get the current system date time but it is giving wrong values any solution for this..

Ah, time and the CF and WinCE. What fun! Along with all the other fine answers you've received there are other things to know:
The OS stores LocalTime, not UTC so GetSystemTime ends up getting LocalTime and them adjusting that backwards based on your timezone and DST, so if the local time is right but SystemTime is not, then you have a TZ or DST setting wrong.
DST may or may not be right due to congress changing it, so a QFE may be required by the OEM
DST may be on or off in the registry
The CF caches timezone bias as startup, so any adjustment of the timezone renders DateTime.Now incorrect until you restart your app
Not all devices can persist time across a power loss (or even a reset)
Time will "float" throughout the day. how badly (milliseconds to seconds) depends on the actual hardware implementation

Why don't you use DateTime.Now ?

What is the problem?
Is your p/invoke signature correct?
Is you struct laid out correctly?
How are you dealing with the struct pointer being 'returned' ?

If the time returned is off by one hour, then you're running into a Daylight Savings Time bug (which can be fixed with a hotfix).
GetSystemTime returns the Coordinated Universal Time (UTC). You may be looking for just the local time, in which case you want to call GetLocalTime instead (or just use DateTime.Now or DateTime.UtcNow, and skip the PInvoke stuff).

What do you mean by wrong values?
Since you are asking about Windows CE, it might be that your system does not save the RTC and does not sync on boot resulting in not having the correct time at all.
This is platform specific. Is the time and date correct in the taskbar (assuming you have that in the image)?

Related

<DateTimeInput> converts time to UTC when saving

Thanks for adding DateTimeInput! I have a bit of a problem with it, though. It converts the entered time into UTC using my local timezone (decreases 2 hours from the entered time). Is there a way to make it simply save the time that's entered?
I didn't find any info about any options this component accepts.
EDIT:
Nobody has any answer to this problem? I'm sure I'm not the only one who wants to be able to store date/time values from the UI "as-is", instead of some automatic conversions.
In our case we enter certain measurement data from different locations. The location of the UI user here is irrelevant and the automatic conversion simply messes things up.

expire application after 1 year span from client PC, No internet is available on client PC

I have one vb.net windows application and I want to deliver it to my client with 1 year validity.
After one year this software will automatically stop working or ask for renewal.
The client PC doesn't have internet access.
Please tell me the secure way for this.
When the program is installed, have it set a registry value with the current date. Then, on every subsequent program start, have it check that registry value against the current time. If more than a year has passed, do whatever you plan on doing to lock up your application.
This post has some excellent info on the specifics of adding, modifying, and accessing registry values in vb.net.
Check the date.
If dateToday > dateProgramSold.AddYears(1) Then
'open form that cant be close saying program is expired
End If
When the program is installed, it should ask for an registration key (they could get it by email, print it off and type it). The key should contain the last day of validity (encrypted). Store the key in the registry (or somewhere else). When the program starts, you check the date inside the key.
If they re-install the end date will stay the same.
When they want to update, just send a new key by email or mail.
The amount of security you put into just could depend on how much you trust the company. Because they could always decompile and crack your software.
I needed to do this for a program I wrote. My final solution included the resolution that you can't be 100% foolproof, so I considered my users and did the best I could with what I had.
Without access to the internet, how does the computer know what date it is? It has to rely on user input for it. So if a user can input it, then a user can change it. There is no foolproof way to get an accurate date from the PC without the the user having access to it. Whether from the OS, the BIOS, etc.
So what I ended up doing was putting an obfuscated key into the registry in an obscure place. HKCU >> Software. I made the key just some letters and numbers {L12A3C0DFF} then I named the key Z0B0 and made the value the obfuscated date. I took the year month and day and ran each one through a different calculation. I ended up with something that looked like DDE011468932.
Each time the program ran it decoded this registry setting to see if a year had passed based on the time in the BIOS. If the date in the BIOS was earlier then this date then they changed it and I would not not allow my program to run.
Also each time the program ran, I checked the date in the BIOS and stored this in the registry in the same way. So I would check to see if they changed the date in the BIOS to an earlier date.
So in order for them to abuse the date restriction of one year, they literally had to change the date in the BIOS every day which I figured was not worth it to them to do, besides, they would have had to figure out where I was getting the date from to begin with, which would take decompiling (and I wasn't selling it to a bunch of programmers). Simply changing the date in the OS wouldn't fool it.

Date reflects incorrectly due to Time Zone setting on Sharepoint

We're using an Access application that stores and retrieves information from SharePoint, and the times and dates get viewed through the 'filter' of the Time Zone settings on SharePoint.
This has started to cause a problem when just trying to enter a date with no time. People marked as CST will see 7/1/2014 0:00, but those in PST will see 6/30/2014 22:00. Calculations that organise metrics by date would then show the same entry in June for PST users and July for CST.
Is there a way to adjust for this? I don't WANT to be capturing a time in this field, but since it's a Date/Time field on SharePoint, it's attaching a time anyway. Would changing the field in question to 'String' work or would that cause more problems than a more adaptive solution?
(I've read links that popped up in 'Questions that may already have your answer', conducted other searches on and off Stack.)
After a bit of testing after all my Users went home except for one, I found that just changing the type on SharePoint for the fields in question from 'Date/Time' to 'Text (Single Line)' worked perfectly. My Tester had no issues with the VB used to store information and bringing up the raw tables showed the 'proper' date stamps after a restart of the client database.
It seems a little too good to be true, but it appears to be a victory! I'll definitely come back here with an update if anything blows up.

How to implement a trial period for a objective c/cocoa mac osx app?

I'm getting started with Objective C and Cocoa on Mac and i would like to develop a app that will have a trial period of 30 days for example like most of the apps have.
How can this be implemented on Mac OSX? Do i store somewhere the installation date and then on each run i check for that? Or what is the general way of achieving this?
That is certainly one way to check the expiry of a trial, but I've found that implementing time based trials can be troublesome when dealing with slightly cleverer users.
If you use a time trial (i.e. 30 days) how do you check the time? You can store the time that the app was installed, and you can read the current time to work out the difference, but how can you guarantee the time(s) you are reading is correct. The user may have edited one or both of these values. (By changing your stored value if it's not encrypted or by changing the system time).
You could use the Internet to verify the time, but what would you do if the user isn't connected to the Internet?
I'm sure there will be more sophisticated ways of checking how long the user has had the program installed, but I'm afraid I can't enlighten you to any.
I'd consider one of the alternatives methods of providing a trial:
Number of times the app has been started - (take into account that your app may crash, or the user may keep the app open). You may wish to count instead, the number of days on which the app has been opened and allow the user to open the app on 15 different days.
Restricted Content - Make a separate target for your app with less content. This is a safer way to ensure that the user can't work around your restrictions, but it's also more work for them to install a separate version. Consider that you may lose some sales.

Get system time in VB.NET

How do I get the system time using VB.NET and copy it into the clipboard automatically?
Is there a built-in function in VB.NET for this?
I'm not sure what you mean by System Time, but if it's just the string representation of the current time then you can do the following.
ClipBoard.SetText(DateTime.Now.ToString())
This code will work in both Windows Forms and WPF.
Use DateTime.Now to get the time and Google for the code to copy to the clipboard.
Or take a look at this post.
Better use the DateTime.UtcNow method.
It returns time without local format and DST offset.
UTC will keep you out of trouble when storing data.
You can always format to local when export/display is needed.