|
Hey my friends ... I have one application done in C# .. but i want to give it for my customers as a trial version (I want it to count from the day it installed up to 30 days) ... But if i use DateAndTime class ... I think if they change the date and time ... so that i can be faked .... can any body help me with this problem .... or how can i get the real date even if they change it ... i.e like other softwares do ... just count from the day it is installed ....
Thank you a lot
|
|
|
|
|
Any or all of:
0) I wouldn't bother.
1) Store the date and time of install or first use and then calculate the elapsed time when it starts up.
2) Have it access a website to get the current date and time rather than use the system clock.
3) Have it access your site (phone home) to determine the date and time and elapsed time.
|
|
|
|
|
One could also use Environment.TickCount to infer that the time has been changed or the computer has been restarted. If tick count and date are stored together at each use, that can be compared against a later reading. This would not be perfect detection (it would be easy to get around), but it could be used to detect the types of modifications that many users would make.
But, it's probably too much work. Doing a simple time check to a remote server would be enough to deter most users from subverting the trial.
Also, there are other forms of trials. For example, usage could be limited based on how long the application is left open. This could be more easily tracked than the amount of time it's been installed.
|
|
|
|
|
Make a remote call to a server that you control to get the date/time. They can't change the clock on your server.
|
|
|
|
|
My application is only for 1 PC ... i.e there are no servers or other PC's around there ... There is no internet or cant interact with websites ... it is just for a stand alone computer
|
|
|
|
|
Then do what I said here and make the trial based on the total number of hours the application has been open.
|
|
|
|
|
and what is keeping the user from installing the trial app over and over again?
|
|
|
|
|
The installation could store the the number of hours open in the registry. The app could check if that exists at install time. If it doesn't, it creates it. If it does, it leaves it as is. When the app is opened, it makes note of the number of ticks that have passed... when it is closed (and perhaps periodically in case the user forces the application close without proper finalization) it will take note of the ticks again, calculate the difference, and add that to the value in the registry.
Of course, the user could get around that, but users can get around most anything. That should be sufficiently difficult to prevent most users from toying around with it. Some more ideas to make it more secure:
- Do some basic encryption (even with a known/static password) on the value in the registry so the user can't just open regedit and change the value to their liking. Of course, they could remember one of the previously encrypted values, if they thought of that. Or delete the key altogether, but there are ways to detect that too (and ways to get around it, and so on).
- Make the EXE modify itself to make note of the value stored in the registry. If it doesn't match the next time the app is run, that means the user did some tampering. This will be sufficiently non-obvious to trip up most users.
- Create a hidden folder in one of several predetermined but randomly chosen locations. If that folder exists, it means the app was installed before. This will get in the way of users who like to just delete registry keys and reinstall trial apps.
There are various solutions to problems like this, but very simple solutions will trip up the majority of users.
|
|
|
|
|
|
You can do one of two things I recon.
1) Store the date of first install in the registry.
2) Store the date of first install in an encrypted file in app directory.
In either of the two means above, you check the install date in either the registry or the encrypted file and calculate the days remaining from there. Once it has reached 30 days then you set all controlls on the form to falls or just pop up a messagebox to say that the trail has expired and close the app down once OK has been pressed.
If you want the fancy stuff then you may have to spend lots of money to buy an MSI builder or exe builder. I recon the above is much cheaper and should only take a few minutes to code into the app.Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hey dude ... u've a nice idea .. but what really my question is ... if the user changed the date ...
For e.g .. I installed the app 2 day and today is ..>> 3/5/2010 .. and it is saved in registry ... lets say aftr 15 days ... that is ..>>>3/20/2010 ... if the user changes the time to 3/10/2010 ...It means they faked me 10 days ... and they can do zis forever ... how can i controll this .. thx a lot
|
|
|
|
|
Where in Toronto Ont Canada can I walk in and buy Visual Studio 2008 ?
|
|
|
|
|
Don't think I've ever seen Visual Studio in a physical store (though my coworker says he bought a copy in some student store). Why not buy it online? Or maybe visit a university and see if you can buy a copy from their student store?
|
|
|
|
|
I have... but not recently. (2002)
|
|
|
|
|
For about a thousand bucks (CDN), you can have it delivered to you in 24 hours from Amazon[^].
/ravi
|
|
|
|
|
There's no Microsoft Store near you yet?
|
|
|
|
|
hi,
how do i read and write date from/to xml file?
my xml looks like this (it's basically the app config):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Setting1" value="Very" />
<add key="Setting2" value="Easy" />
</appSettings>
</configuration>
for example i found that to read date from xml,i can do this:
DataSet myDS = new DataSet();
myDS.ReadXml(@"C:\appconfig.xml", XmlReadMode.ReadSchema);
Similarly, how can I write to xml using datasetmodified on Thursday, March 4, 2010 7:07 PM
|
|
|
|
|
Dude,
A quick Google Search[^] would have led you to the First Search Result.[^]
The code from the website is
System.IO.StreamWriter xmlSW = new System.IO.StreamWriter("Customers.xml");
custDS.WriteXml(xmlSW, XmlWriteMode.WriteSchema);
xmlSW.Close();
I'm not trying to pick on you with all of the links. I am just trying to show that a little searching would give you the answer you need right away. Instead, you had to wait almost 4 hours for me to reply.
Good luck writing out your data!
Hogan
|
|
|
|
|
hi,
tks for the reply but i noe how to read with your code given.
what i'm looking for is how do you proceed after that? with my given xml, how do i get the value of the key and its value.
for example:
<add key="Setting1" value="Very" />
how do you get the value of Setting1;
and how do you update this value.
similarly how do you create new element and value with dataset.
i tried using the dataset table but im pretty much lost as it provide null value.
|
|
|
|
|
|
Language: C# 2.0
IDE: VS2008 Professional
OS: Windows Vista Home Premium SP2
(Just in case any of this information is needed)
Alright, I'm in the process of writing some software mostly for the fun of it, though it will be useful to others as I have already talked with people about it. Anyhow, on to my issue.
Well, when I started writing the application (a Record Label management system) I was using really inefficient methods and such. I was using things that were not necessary and I wanted this to be more of a quality application than just a "slap-together" project. So I started re-writing some code, re-creating some forms, and so on. The application is MDI and the child windows are for things such as managing sessions, artists, sales, etc.
I have this code which is used to delete an artist. The 'RecordLabel' class is a simple class I wrote that handles the main file I/O (saving/loading the record label data to/from a file). It is referenced like this "RecordLabel recordLabel" in the "MainForm" class. Here is the code from "ArtistsForm":
public Artist GetArtistData()
{
Artist newArtist;
if (null == (newArtist = new Artist()))
return null;
newArtist.UniqueId = txtUniqueId.Text;
newArtist.StageName = txtStageName.Text;
newArtist.FirstName = txtFirstName.Text;
newArtist.LastName = txtLastName.Text;
newArtist.PrimaryPhone = txtPrimaryPhone.Text;
newArtist.SecondaryPhone = txtSecondaryPhone.Text;
newArtist.Email = txtEmail.Text;
newArtist.HomePageUrl = homePageLink.Text;
newArtist.MyspaceUrl = myspaceLink.Text;
newArtist.SoundclickUrl = soundclickLink.Text;
newArtist.HourlySessionRate = txtRecordingRate.Text;
newArtist.Notes = txtNotes.Text;
if (sessionsList.Items.Count > 0)
{
foreach (ListViewItem session in sessionsList.Items)
newArtist.SessionIdList.Add(session.SubItems[0].Text);
}
return newArtist;
}
public bool IsSelectionValid()
{
if ((artistsTree.Nodes[0].Nodes.Count > 0) && (artistsTree.SelectedNode.Level > 0))
return true;
else
return false;
}
private void btnDelete_Click(object sender, EventArgs e)
{
Artist artist;
if ((null != (artist = GetArtistData())) && (IsSelectionValid()))
{
DialogResult result = MessageBox.Show("Are you sure you want to delete the artist named \"" +
artist.StageName + "\"? This operation cannot be undone.", "L.M.E. - Delete Session",
MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.Yes)
{
MainForm parentForm;
if (null != (parentForm = (MainForm)this.MdiParent))
{
if (parentForm.DeleteArtist(artist))
{
if (artist.UniqueId != string.Empty)
{
TreeNode node = artistsTree.SelectedNode;
if (node != null)
{
artistsTree.Nodes[0].Nodes.Remove(node);
if (Artists.Count == 0)
System.Diagnostics.Debug.WriteLine("Artists.Count = 0");
foreach (Artist a in Artists)
{
System.Diagnostics.Debug.WriteLine("Unique ID: " + a.UniqueId);
if (a.UniqueId == artist.UniqueId)
{
System.Diagnostics.Debug.WriteLine("Removed: " + a.UniqueId);
System.Diagnostics.Debug.Write("\tArtist ID:" + artist.UniqueId);
Artists.Remove(a);
return;
}
}
}
}
}
}
}
}
}
I have used the Debug.WriteLine and Debug.Write functions in order to (hopefully) find the problem. However, I have had no such luck and I am no closer to the solution than when I originally started to encounter this issue.
Here is the 'MainForm.DeleteArtist' method:
public bool DeleteArtist(Artist artistData)
{
if ((recordLabel == null) || (recordLabel.Artists == null) || (recordLabel.Artists.Count == 0))
return false;
foreach (Artist artist in recordLabel.Artists)
{
if (artist.UniqueId == artistData.UniqueId)
{
recordLabel.Artists.Remove(artist);
switch (recordLabel.SaveDataToDisk(CurrentDataFilePath))
{
case IoErrorCode.NoError:
sessionTimerForm.Artists = recordLabel.Artists;
sessionsForm.ClearArtistsList();
sessionsForm.Artists = recordLabel.Artists;
sessionTimerForm.RemoveArtist(artistData.StageName);
currentActionStatus.Text = "Data saved successfully.";
currentActionStatus.Image = Lab_Management_Environment.Properties.Resources.preferences;
return true;
default:
return false;
}
}
}
return false;
}
Now for the problem. I create two or three example artists and all goes well. It saves all the data appropriately and I can select each artist and the artist's data is displayed properly in all of the input fields.
Once I delete any artist (first, last, third, whatever) it empties my "List<artist> Artists;" object in the "ArtistsForm" class. I have made sure that it is only deleting the artist with the selected artist's ID, and it's correct.
However, it only gets to this point in the code (from "ArtistsForm"):
if (parentForm.DeleteArtist(artist))
{
if (artist.UniqueId != string.Empty)
{
TreeNode node = artistsTree.SelectedNode;
if (node != null)
{
artistsTree.Nodes[0].Nodes.Remove(node);
if (Artists.Count == 0)
System.Diagnostics.Debug.WriteLine("Artists.Count = 0");
No matter what, it hits the "WriteLine" there. It seems to only happen after the call to "parentForm.DeleteArtist". Any suggestions? This is really irritating me. :-P But I've been patient with it and I can wait for a response. I'm in no hurry and this isn't a work project so I have no deadline.
I apologize for any sloppy coding and such. I'm just trying to get this working before I clean it up. I don't really like looking at this code much anymore because my standard coding practice is quite neat and well put together (at least to me).modified on Thursday, March 4, 2010 9:55 PM
|
|
|
|
|
Hi Matt,
I didn't spot the problem you reported right away; however I do have lots of comments, I'll give you some here, as I hope they will inspire you; taking care of them should simplify your code, possibly also eliminating the problem:
1.
Your Artist class is holding strings, even for items that basically are not strings: UniqueID would be better of being an int, HourlySessionRate probably needs to be a float/double/decimal, maybe an int, but not a string.
And yes, that means you need to use a Parse/TryParse method to convert user input to a number, and also ToString() to turn a number to a string for output purposes; but then you can use the numbers to perform calculations, indexing, etc.
2.
you have too many safety tests. Examples:
a) a constructor (e.g. Artist) should either return a real object, or throw an exception; it should never return null.
b) no need to test for an empty list, a foreach will just be skipped when the list is empty.
3.
I tend to name collections by using the plural of the type name they contain. So "students" would be an array, a list, a queue, whatever, holding Student instances. And I don't include "array", "list" or whatever, so I can easily change my mind later on.
4.
Since UniqueID is an important field to your Artist class, why not store Artist instances in a Dictionary<int, Artist> collection? That eliminates searches by UniqueID, just do Artists[UniqueID] as a dictionary can be indexed just like an array.
5.
at the end of btnDelete_Click, you have a foreach loop which attempts to modify the collection you are enumerating; that won't work, as a removal invalidates the enumerator. I expect it throws an exception.
6.
you seem to have several methods that return a bool to indicate success/failure. Most often that is not the best way to do error checking as it forces you to write extra code on every invocation; if you forget some, errors will go unnoticed. The modern way if dealing with this, is by throwing an Exception when something went wrong; then the caller can get that information using one or more try-catch blocks. If you're unfamiliar with them, take the time to read up on it, it comes in very handy.
7.
when catching an exception, NEVER ignore it; either solve the situation in your app, or at the very least report it somewhere, using all available information.
try {
...
} catch(Exception exc) {
Console.WriteLine(exc.ToString());
}
is what I do most of the time. It will tell you exactly what went wrong and where, up to the source line.
|
|
|
|
|
Well, it sucks that you can't find a problem with it. :-P But I do appreciate all the feedback/suggestions for sure. I'm always looking for ways to improve my ability (I'm self-taught; no formal education in the field).
I didn't know anything at all about the Dictionary but I've seen it in articles before. I will definitely take the time to learn how to use them.
The "UniqueId" property in the "Artist" class would be a string. It's generated using numbers as well as letters. I don't know why I didn't think of using a Double for GlobalRecordingRate. I'm doing that the opposite way. In one part of the application it makes calculations using the rate string something like "double Rate = double.Parse(GlobalRecordingRate)", LoL.
The feedback is greatly appreciated.
Now I hope someone can help me with this issue. I'm continuing to investigate on my own, of course. I don't expect others to solve my problem alone when I can't figure it out over time. :-P Anyone have any ideas?
|
|
|
|
|
Even when UniqueID is a string, you can still use it as the key (or index) for a dictionary, so finding the artist of interest would be automatic. Or you could add an int field ("key") that is unique and strictly internal to your app.
I didn't say I can't find the problem, I just didn't see it right away; I am stumbling all to often over things I would do completely differently. With my comments, you could simplify your code, making it much easier to see any remaining problems.
I do have some problem understanding the logic you're applying. You have a delete method that saves data to disk? And as I said, the actual removal is bound to fail, aren't you getting an InvalidOperationException?
|
|
|
|
|
I am looking forward to updating the code to follow your recommendations. I just don't have a lot of time at the moment. I simply wanted to fix this issue.
No, I am not receiving any sort of exception in the area you mentioned. However, I did solve the problem. It was a very strange cause and I really don't understand why it caused the problem. The following line of code caused the issue:
sessionsForm.ClearArtistsList();
which called "Artists.Clear();" in the "SessionsForm" class. The reason I don't understand the issue is because "Artists" is an entirely separate "List" object in an entirely different form's class file. However, making the call to "Artists.Clear()" was unnecessary and now that I look at it I'm wondering why the heck I ever put that in there to begin with.
Thank you very much for the help. I'll be looking into each of your suggestions this weekend (when my schedule permits) in order to understand how they will help me. I will then apply those techniques where needed.
By the way, I call "SaveDataToDisk" because the application has taken a different path than originally intended. I thought the application would be rather small, containing minimal data. But now that I've turned it into the beast that it is (:-P) I am going to have the user manually save via the standard "File->Save", as well as implementing an auto-save feature.
|
|
|
|
|