views:

100

answers:

3

I have winform application written in c#. I would like this application to only gets installed in a single machine e.g. M1. If a user tries to install the application in M2, he/she will get an error says "installation aborted due to .... etc".

I will have to check MAC Address and Machine Name, if they match the one hard-coded in the application then carry on. Otherwise, quit installation.

Any idea what steps should i take and where should i put this snippet?

A: 

As to where you should put the code - put it in the program startup method:

public static void Main()
{
    if (licenced)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new YourForm());
    }
    else
    {
        // Display error
    }
}

as others have pointed out in their comments - it can be relatively easily removed, but if you're sure your user won't tamper with the code then it should do the job.

You could check the disk ID, CPU ID etc. See this Code Project article. Checking a combination would make it less likely that someone would be bothered to change all the values you are checking.

Though you would need access to the machine to get this information first and it will mean that if the user changes any of the hardware you check the program will stop working.

ChrisF
I imagine that including IDs of hardware devices would break the app if they ever upgrade their hardware. CPU upgrades are rare but graphics cards and hard drives are replaced frequently, even by non-technical users.
FrustratedWithFormsDesigner
@Frustrated - good point.
ChrisF
A: 

Assuming the user is completely non-technical, you could control all of this through configuration files. The first time the app runs, it gets the MAC address and machine name (like you want) and stores them in a file. The file should probably be encrypted. Every time the app starts up after that, it has to look at that file and ensure that the machine name it's running on and the MAC address of that machine match what is in the file.

This scheme could be broken by changing the MAC address or the machine name - it would cause the app to break. The scheme could be defeated if the file with the machine name/MAC address were given to other users who then changed their MAC address/machine name to match. There are probably other ways I haven't even thought of yet.

And since you ask where the code snippet should go, I'll say it should go near app startup, but without seeing your code it's really not possible to say more than that.

FrustratedWithFormsDesigner
This won't stop the program being run on another machine.
ChrisF
@ChrisF: Why the downvote? I pointed out that this scheme has flaws. Most of them won't apply to non-technical users, but since they aren't the sort who are likely to try and hack it, I think this will work for OP's purposes.
FrustratedWithFormsDesigner
@FrustratedWithFormsDesigner I didn't downvote. I comment first as the point is to improve the answers.
ChrisF
@ChrisF: Ah, ok then, never mind. The timing on this end made it look like both events were at the same time.
FrustratedWithFormsDesigner
+1  A: 

Protecting your software with a combination of the machine name (you can change it easily) or a MAC address (you can create virtual network card with the MAC address you want easily), will not work long term.

I suggest you to use a HASP key:

http://www.aladdin.com/

Or authenticate online... this is cheaper, but your software has to be on the computer with an internet connection

And if protecting your software is really important to you, don't try to do it yourself. Use a professional solution. Here is one that do exactly what you want: http://www.eziriz.com/intellilock.htm

Pierre 303
And all of this will work if your software is sold to very few number of people (for exemple is very specific to an industry). If your software is widely used in the world, it will be cracked, regardless the protection you use.
Pierre 303
Yes, my application is very specific...
Beginner_Pal
How much copies you think you will sell ?
Pierre 303
@Pierre 303: Considering OP said "one machine only", I assume one (and probably no plans for further sales if it's a highly customized, one-off system). And it has probably already been partly paid for.
FrustratedWithFormsDesigner
@FrustratedWithFormsDesigner: I do think that hard coding check is the cheapest and most effective solution ;)
Pierre 303
@Pierre 303: If you only plan to do one or two installations of this system *ever*, then yes, a hard-coded license is probably easiest and best for the situation. Just keep in mind you may be called to "refresh" the license should the target machine's name/MAC address ever change.
FrustratedWithFormsDesigner
It is a single application that should work on a specific person's PC. Highly specific, the application not to be sold. Pierre your solution worth looking at for general/retail applications.
Beginner_Pal