Вы находитесь на странице: 1из 6

12/24/13

10,283,701 members (59,076 online)

Application Trial Maker - CodeProject


Sign in

home

articles

quick answers

discussions

features

community

help

Search for articles, questions, tips

Articles Languages C# General

Next

Article Browse Code Stats Revisions (4) Alternatives Comments & Discussions (207)

Application Trial Maker


By Hamed J.I, 16 Feb 2009
Sign Up to vote 4.69 (153 votes)
Tw eet 1 6 Like 33

About Article
A library to easily create a trial version of your application Type Licence Article CPOL 6 Sep 2006 276,905 63,128 385 times

Download source files - 72 Kb Download Example files - 70 Kb Download Serial Maker files - 46 Kb Download SerialBox Control files - 34 Kb Download FilterTextBox Control files - 19 Kb

First Posted Views Downloads Bookmarked

.NET2.0 VS2005 C#2.0

Introduction

Windows Dev , +

It's very common to want a trial version of your application. For example, you need your application to only run for 30 days, or the user can only run your application 200 times. You can do this kind of task with this library. If someone wants to buy your application, he must call you and read his computer ID. Then you will use the Serial Maker to make a serial key (password). After entering the password, the application always runs as the full version. If the trial period is finished, reinstalling the application won't let user run it. The computer ID is a 25 character string that came from hardware information. Processor ID, main board manufacturer, VGA name, hard disk serial number, etc. You can choose what hardware items you want to use to make the computer ID. When you give the password to a customer, his password won't change until he changes his hardware.

Top News
Microsoft bets on Windows XP disaster
Get the Insider News free each morning.

Computer ID
To make a Computer ID, you must indicate the name of your application. That's because if you have used Trial Maker to make a trial for more than one application, each application will have it's own Computer ID. In the source, Computer ID = "BaseString" Trial Maker uses management objects to get hardware information.

www.codeproject.com/Articles/15496/Application-Trial-Maker

1/6

12/24/13

Application Trial Maker - CodeProject

Serial
The password will be produced by changing the Computer ID. To make a password, you must have your own identifier. This identifier is a 3 character string. None of characters must be zero.

Related Videos

Files
There are two files to work with in this class. The first file is used to save computer information and remaining days of the trial period. This file must be in a secure place, and the user must not find it (R e g F i l e ). It's not a bad idea to save this file in application startup directory The second file will be used if the user registers the software. It will contain the serial that the user entered (H i d e F i l e ). You can save HideFile in, for example, C:\Windows\system32\tmtst.dfg. I mean some obscure path. Both files will be encrypted using Triple DES algorithm. The key of encryption is custom. It's better you choose your own key for encryption.

Related Articles
Creating Secure Trial Versions for .NET Applications - A Tutorial Implementing a Rudimentary Count Based Trial Version Plugin for Windows Applications What Goes Into the Ultimate User Interface? Molecular Clinical Trials: MCT Understanding the Why, What, and How of Reporting Solutions: Reporting 101 Asynchronous Progress Using Microsoft.DirectX.AudioVideoPlayback in C# Understanding the Sea of Data: Infragistics Helps Developers Visualize Data ImageList Wizard Title: 5 Lessons Learned Extending On-Premise Software to The Cloud From .NET Reporting to Business Intelligence: How software developers today are unleashing critical business efficiencies across the board LyricsFetcher - The Easiest Way to Find Lyrics for your Songs Demonstration of selectOneMenu tag in JSF Shareware registration dialog Controlling Demo-Version Crack and Software Piracy Issue for Beginners - Part 1 Snow Ninja 7 Questions You Always Wanted to Ask about Content Management Systems Visualizing the Windows Mobile Virtual Memory Monster How to integrate Usercontrols in LightSwitch Application? XSL Transform for ToDoList Use Rules In Your Applications

How it works
Getting System Information
S y s t e m I n f oclass is for getting system information. It contains the G e t S y s t e m I n f o function. This function takes the
application name and appends to it the Processor ID, main board product, etc.
Collapse | Copy Code

p u b l i cs t a t i cs t r i n gG e t S y s t e m I n f o ( s t r i n gS o f t w a r e N a m e ) { i f( U s e P r o c e s s o r I D= =t r u e ) S o f t w a r e N a m e+ =R u n Q u e r y ( " P r o c e s s o r " ," P r o c e s s o r I d " ) ; i f( U s e B a s e B o a r d P r o d u c t= =t r u e ) S o f t w a r e N a m e+ =R u n Q u e r y ( " B a s e B o a r d " ," P r o d u c t " ) ; i f( U s e B a s e B o a r d M a n u f a c t u r e r= =t r u e ) S o f t w a r e N a m e+ =R u n Q u e r y ( " B a s e B o a r d " ," M a n u f a c t u r e r " ) ; / /S e em o r ei ns o u r c ec o d e S o f t w a r e N a m e=R e m o v e U s e L e s s ( S o f t w a r e N a m e ) ; i f( S o f t w a r e N a m e . L e n g t h<2 5 ) r e t u r nG e t S y s t e m I n f o ( S o f t w a r e N a m e ) ; r e t u r nS o f t w a r e N a m e . S u b s t r i n g ( 0 ,2 5 ) . T o U p p e r ( ) ;

Then it removes unused characters from the string. Any characters outside the range A to Z and 0 to 9 are unused characters. If the string isn't long enough, call G e t S y s t e m I n f o A g a i nto make it longer.

R u n Q u e r yfunction takes object name (T a b l e N a m e ) and method name and returns defined method of first object
Collapse | Copy Code

p r i v a t es t a t i cs t r i n gR u n Q u e r y ( s t r i n gT a b l e N a m e ,s t r i n gM e t h o d N a m e ) { M a n a g e m e n t O b j e c t S e a r c h e rM O S= n e wM a n a g e m e n t O b j e c t S e a r c h e r ( " S e l e c t*f r o mW i n 3 2 _ "+T a b l e N a m e ) ; f o r e a c h( M a n a g e m e n t O b j e c tM Oi nM O S . G e t ( ) ) { t r y { r e t u r nM O [ M e t h o d N a m e ] . T o S t r i n g ( ) ; } c a t c h( E x c e p t i o ne ) { S y s t e m . W i n d o w s . F o r m s . M e s s a g e B o x . S h o w ( e . M e s s a g e ) ; } } r e t u r n" " ; }

Once we have system information, we must make a Computer ID (B a s e S t r i n g ) from it.

Related Research

Making Computer ID (BaseString)


Collapse | Copy Code

p r i v a t ev o i dM a k e B a s e S t r i n g ( ) { _ B a s e S t r i n g= E n c r y p t i o n . B o r i n g ( E n c r y p t i o n . I n v e r s e B y B a s e ( S y s t e m I n f o . G e t S y s t e m I n f o ( _ S o f t N a m e ) , 1 0 ) ) ; }

Custom API Management for

www.codeproject.com/Articles/15496/Application-Trial-Maker

2/6

12/24/13

Application Trial Maker - CodeProject


To make B a s e S t r i n g , first we get system information, and then use E n c r y p t i o n . I n v e r s e B y B a s e and E n c r y p t i o n . B o r i n g .
the Enterprise: Learn how to build a successful API strategy [Webinar]

I n v e r s e B y B a s e :E n c r y p t i o n . I n v e r s e B y B a s e ( " A B C D E F " , 3 )will return CBAFED; it's so simple - it's inversing


every 3 characters Boring: move every character in the string with the formula:
Collapse | Copy Code

N e w P l a c e=( C u r r e n t P l a c e*A S C I I ( c h a r a c t e r ) )%s t r i n g . l e n g t h

Making Serial key (Password)


We use E n c r y p t i o n . M a k e P a s s w o r d . this function takes B a s e S t r i n gand I d e n t i f i e r . It uses I n v e r s e B y B a s e3 times and B o r i n gonce, and then use C h a n g e C h a rfunction to change characters
Collapse | Copy Code

Insider Secrets for Avoiding a Malware Breach: Best Practices for Securing Your Private Keys and Code Signing Certificates

s t a t i cp u b l i cs t r i n gM a k e P a s s w o r d ( s t r i n gs t ,s t r i n gI d e n t i f i e r ) { i f( I d e n t i f i e r . L e n g t h! =3 ) t h r o wn e wA r g u m e n t E x c e p t i o n ( " I d e n t i f i e rm u s tb e3c h a r a c t e rl e n g t h " ) ; i n t [ ]n u m=n e wi n t [ 3 ] ; n u m [ 0 ]=C o n v e r t . T o I n t 3 2 ( I d e n t i f i e r [ 0 ] . T o S t r i n g ( ) ,1 0 ) ; n u m [ 1 ]=C o n v e r t . T o I n t 3 2 ( I d e n t i f i e r [ 1 ] . T o S t r i n g ( ) ,1 0 ) ; n u m [ 2 ]=C o n v e r t . T o I n t 3 2 ( I d e n t i f i e r [ 2 ] . T o S t r i n g ( ) ,1 0 ) ; s t=B o r i n g ( s t ) ; s t=I n v e r s e B y B a s e ( s t ,n u m [ 0 ] ) ; s t=I n v e r s e B y B a s e ( s t ,n u m [ 1 ] ) ; s t=I n v e r s e B y B a s e ( s t ,n u m [ 2 ] ) ; S t r i n g B u i l d e rS B=n e wS t r i n g B u i l d e r ( ) ; f o r e a c h( c h a rc hi ns t ) { S B . A p p e n d ( C h a n g e C h a r ( c h ,n u m ) ) ; } r e t u r nS B . T o S t r i n g ( ) ;

Check Password
After making B a s e S t r i n gand password, check if the user already registered the software. To do this, use C h e c k R e g i s t e rFunction. It will return true if registered before and false if not. If C h e c k R e g i s t e r returns false, open a registration dialog for the user to enter the password.

Show Dialog
Create new f r m D i a l o g and show it to the user. If the dialog result is O K , it means software is registered successfully, and if it is R e t r y , it means it is in trial mode. Any other D i a l o g R e s u l tmeans cancel. The Dialog class takes BaseString, Password, days to end and Run times to end as arguments.

Reading And Writing Files


There's a class named F i l e R e a d W r i t e . This class reads / writes files with Triple DES encryption algorithm.

F i l e R e a d W r i t e . W r i t e F i l etake a 2 strings. The first one is the file path and the second one is the data to write.
After writing all data it write byte 0 as finish. It will use for reading
Collapse | Copy Code

p u b l i cs t a t i cv o i dW r i t e F i l e ( s t r i n gF i l e P a t h ,s t r i n gD a t a ) { F i l e S t r e a mf o u t=n e wF i l e S t r e a m ( F i l e P a t h ,F i l e M o d e . O p e n O r C r e a t e , F i l e A c c e s s . W r i t e ) ; T r i p l e D E St d e s=n e wT r i p l e D E S C r y p t o S e r v i c e P r o v i d e r ( ) ; C r y p t o S t r e a mc s=n e wC r y p t o S t r e a m ( f o u t ,t d e s . C r e a t e E n c r y p t o r ( k e y ,i v ) , C r y p t o S t r e a m M o d e . W r i t e ) ; b y t e [ ]d=E n c o d i n g . A S C I I . G e t B y t e s ( D a t a ) ; c s . W r i t e ( d ,0 ,d . L e n g t h ) ; c s . W r i t e B y t e ( 0 ) ; c s . C l o s e ( ) ; f o u t . C l o s e ( ) ;

The key for writing and reading is the same one, it's custom and you can change it.

How To Use
Where to use
The best place that you can check for registration is before showing the main dialog. When you have created a Windows application project, first you must add SoftwareLocker.dll as reference

www.codeproject.com/Articles/15496/Application-Trial-Maker

3/6

12/24/13

Application Trial Maker - CodeProject


Then in program.cs, find the main function. I think it's the best place for checking registration. You can check registration when your main dialog loads, but before loading is better.

Change Main Dialog


It's better to add one argument to your main dialog constructor. A Boolean value that indicates that this is a trial or a full version running. If it's a trial mode, disable some parts of your application as needed.

How to change main()


Add namespace
Collapse | Copy Code

u s i n gS o f t w a r e L o c k e r ;
Collapse | Copy Code

[ S T A T h r e a d ] s t a t i cv o i dM a i n ( ) { A p p l i c a t i o n . E n a b l e V i s u a l S t y l e s ( ) ; A p p l i c a t i o n . S e t C o m p a t i b l e T e x t R e n d e r i n g D e f a u l t ( f a l s e ) ; T r i a l M a k e rt=n e wT r i a l M a k e r ( " T M T e s t 1 " , A p p l i c a t i o n . S t a r t u p P a t h+" \ \ R e g F i l e . r e g " , E n v i r o n m e n t . G e t F o l d e r P a t h ( E n v i r o n m e n t . S p e c i a l F o l d e r . S y s t e m )+ " \ \ T M S e t p . d b f " , " P h o n e :+ 9 82 18 8 2 8 1 5 3 6 \ n M o b i l e :+ 9 89 1 22 8 8 1 8 6 0 " , 5 ,1 0 ," 7 4 5 " ) ; b y t e [ ]M y O w n K e y={9 7 ,2 5 0 , 1 , 5 , 8 4 ,2 1 , 7 ,6 3 , 4 , 5 4 ,8 7 ,5 6 ,1 2 3 ,1 0 , 3 ,6 2 , 7 , 9 ,2 0 ,3 6 , 3 7 ,2 1 ,1 0 1 ,5 7 } ; t . T r i p l e D E S K e y=M y O w n K e y ; / /i fy o ud o n ' tc a l lt h i sp a r tt h ep r o g r a mw i l l / / u s ed e f a u l tk e yt oe n c r y p t i o n T r i a l M a k e r . R u n T y p e sR T=t . S h o w D i a l o g ( ) ; b o o li s _ t r i a l ; i f( R T! =T r i a l M a k e r . R u n T y p e s . E x p i r e d ) { i f( R T= =T r i a l M a k e r . R u n T y p e s . F u l l ) i s _ t r i a l=f a l s e ; e l s e i s _ t r i a l=t r u e ; } A p p l i c a t i o n . R u n ( n e wF o r m 1 ( i s _ t r i a l ) ) ;

Don't move first two lines, after them, define T r i a l M a k e rclass

Constructor
S o f t w a r e N a m e : Your software's name, this will be used to make ComputerID R e g F i l e P a t h : The file path that, if the user entered the registration code, will save it and check on every run. H i d d e n F i l e P a t h : This file will be used to save system information, days to finish trial mode, how many other
times user can run application and current date. T e x t : It will show below the OK button on the Registration Dialog. Use this text for your phone number, etc. D e f a u l t D a y s : How many days the user can run in trial mode. D e f a u l t T i m e s : How many times user can run the application. I d e n t i f i e r : Three character string for making password. It's the password making identifier

Optional and recommended


In the constructor, you can change the default Triple DES key. It's a 24 byte key, and then you can customize Management Objects used to make the Computer ID (B a s e S t r i n g ):
Collapse | Copy Code

t . U s e B i o s V e r s i o n=f a l s e/ /=t r u e ;

You can do this with any t . U s e X x x Don't disable all of them or none of them, enabling 3 or 4 of them is the best choice. Or you can leave it as its default.

Serial Maker
Serial maker is another application that uses the Encryption class. It takes your identifier and generate a password (serial key) Doesn't contain anything special.

www.codeproject.com/Articles/15496/Application-Trial-Maker

4/6

12/24/13

Application Trial Maker - CodeProject

Other Controls
In the registration dialog, I have used a S e r i a l B o xcontrol. It's only 5 text boxes that you can write your serial in.

S e r i a l B o xuses F i l t e r T e x t B o x itself.
Both of these controls are available to download.

Notes
All codes are written in Visual Studio 2005 Serial Maker uses Encryption class from Trial Maker as a file link Writing with one encryption key and reading with another will cause an exception FilterTextBox Control is not the same that I wrote before in my articles Always Secure your identifiers and don't lose them

License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Hamed J.I
Web Developer Iran (Islamic Republic Of) I began programming with C/C++ when i was 15. Then try to learn VC++ but at the middle of my reading .NET came. I began to read C# and VB.NET and also began designing basic websites by FrontPage and developed some websites for our school and some other companis. Later learn Microcontroller and design some digital circuits with PIC microcontrollers for a industrial controller company. As I learned SQL and ASP.NET developed some website such as news portals that are active now. Now i'm a software student and teach programming in computer institues. And have my own job by getting projects from companies. Article Top

Comments and Discussions


You must Sign In to use this message board. Search this forum Profile popups Spacing Relaxed Noise Medium Layout Normal Per page 25 Go Update

First Prev Next

www.codeproject.com/Articles/15496/Application-Trial-Maker

5/6

12/24/13
any solution to work in windows 7 ? Re: any solution to work in windows 7 ? A simple Dll question Getting a bad data error frmDialog text Renew Trial Maker time Re: Renew Trial Maker time W8 issue Re: W8 issue Re: W8 issue Re: W8 issue My vote of 4

Application Trial Maker - CodeProject


Atif BOUZAGLAOUI lenovi123 pathetic srivatsa6065 jacky13 kunalagnihotri therealtoecutter therealtoecutter therealtoecutter therealtoecutter therealtoecutter rajaonline4u ramesh0285 28-Nov-13 18:44 3-Dec-13 22:02 17-Nov-13 3:15 15-Nov-13 18:10 22-Oct-13 7:54 12-Oct-13 3:05 14-Oct-13 17:57 11-Sep-13 14:48 13-Sep-13 11:59 22-Sep-13 17:12 22-Sep-13 17:43 7-Sep-13 8:36 22-Aug-13 21:18

How to make serial maker Working ,to solve Encryption.cs problem in Serial Maker and Object reference not set to instance of object Wrong password error Many thanks, good work Key changes after re-installing Windows good work ... but fatel error Re: good work ... but fatel error Object reference not set to an instance of an object Re: Object reference not set to an instance of an object

devduttbhatt J.Becker Naresh Dhakecha Member 9910233 Praveen21212 Member 10063932 chandan0285

12-Aug-13 18:48 10-Aug-13 13:45 1-Aug-13 7:56 4-Jun-13 0:43 25-Jul-13 19:32 23-May-13 21:47 21-Aug-13 0:40

Encryption.cs not found Question: what about hiden file"TMSetp.dbf" been found and deleted? My vote of 1 serial maker is not working Re: serial maker is not working
Last Visit: 23-Dec-13 17:54 General News Last Update: 23-Dec-13 21:31 Suggestion Question Bug Answer

Member 10015410 fanorng1985

2-May-13 3:30 21-Apr-13 21:49

Member 9986488 kratika gupta GeekBond Refresh Joke Rant

13-Apr-13 22:19 4-Apr-13 21:12 9-May-13 2:55

1 2 3 4 5 6 7 8 9 Next Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile Web04 | 2.7.131219.1 | Last Updated 17 Feb 2009

Layout: fixed | fluid

Article Copyright 2006 by Hamed J.I Everything else Copyright CodeProject, 1999-2013 Terms of Use

www.codeproject.com/Articles/15496/Application-Trial-Maker

6/6

Вам также может понравиться