How can i make my app. run only if it is on a certain USB Flash Disk?

Hard disk drives have manufacturer serial numbers and i can determine and use them to make my exe run on a certain harddisk only. This provides enough copy protection for me. But now i have to make my exe to run on a USB Flash Disk so that end-user can take it anywhere he wants and run on any computer but it should not run if it is copied to a harddrive, to another flash disk etc. Is there a way to do this? I'm using Delphi 7. Thanks to everyone answering.
Who is Participating?
DavidBirch2dotComConnect With a Mentor Commented:
there you go found it :)

Very long thread but lots of info there all related to the same thing, some of it might be useful

There was a similar thread to this a while ago... unforunatly i cant find it :(  the end result as i remember was that there was no simple way of doing this.  I dont think USB sticks have a unique code....

Why not check the physical size of the drive the exe is on...

If it is larger than the size of a USB drive then halt the exe. :-)

Not too many old 10mb to 1gb hard disks out there any more so this should
work ok...

Also...are not USB drives MUCH slower than the average HD?
do a simple drive access speed test for a couple of seconds
and act accordingly..

Combine both ideas and I bet it would weed out pretty much all HD's
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Checking the S/N of the flash disk, a size check, drive letter (different than A,B,C), file system. This should be almost full-proof. Gonna give code later... Maybe in a few hours.
Speed Test should be skipped. It takes too long and the values can be very different, because of the load of the computer in that moment.
blackcat67Author Commented:
Thanks to DavidBirch2dotcom. I've carefully read all comments at the link you've given. Now I understand that I would not be able to find exactly what i want but some other solutions may work. I'm planning to use a combination of volume serial info and vendor id (or similar info that Windows normally identifies for installation of necessary driver) of the usb disk. But now i should know that how can i determine if my exe runs from a usb disk, or from a hard disk, or even from a cd-rom? And also how can i retrieve the vendor and model info of the usb disk (Such as 3SYSTEM USB FLASHDISK, or  TinyDisk)?

also thanks to romaniankid for comments and i'm waiting for his code.
DavidBirch2dotComConnect With a Mentor Commented:
well, to find out where its running then just get the filename and directory of the exe, i am not sure which letter windows uses for a USB pen... but I think it aught to be something you could pick up on

As for Disk info have a look at - lots of info about getting disk infomation  - get disk free space

Also alot of very good information and components for this kind of task on this site 

and - bottom of the page

Hope that one of those links proves useful,


Can we at least assume you are the person copying your software on the USB device?  If so, you create a strongly encrypted key file that indicates the serial number of the USB device and include that either as a separate binary file on the USB or as a resource file or hard-coded in your program.

As you use new devices, you change the associated serial number check/comparison.

If you want to get really slick, you can copy the files in a specific sequence to the USB device in such a way that the starting sector of the serial number file(s) are in specific locations.  You can use Windows file system API calls to determine the starting location as a valid indicator.

If you are looking for a more secure solution, look to vendors that offer strongly encrypted dongles and associated security software.  Your application can then be installed on the hard drive and require the presence of the data on the strongly encrypted USB dongle in order to execute.
> Comment from DavidBirch2dotCom
>Date: 08/29/2004 03:08PM CEST
>      Comment       

>there you go found it :)
>Very long thread but lots of info there all related to the same thing, some of it might be useful

i followed this this thread and there you can find the followin post:

>Comment from alikoank
>Date: 08/02/2004 10:08AM CEST
>      Comment       

>Ordinary memory sticks do not have an unique ID. They have some sort of hardwareID but it is not unique, and is used to identify usb hardware to host computer.
>There are some memory sticks with unique id feature but they also require installation of drivers to host system.

the whole problem condenses to one simple problem:
is one usb stick different from another one?
that means can you determine within a program that the actual one is not the original one?
its the same problem the cd disc copy protections have.
as blank cds dont have a serial number they developed different means of protections.

in the other thread no one knew something about a unique serial number for usb sticks


I'm glad we could help you solve your problem (thanks for the points).
However, a 'C' grade indicates some dissatisfaction with the comments
or solution.  This discussion thread had only been open for a couple of
days, so I'm surprised that it is now closed.  Perhaps if we had discussed
this further, you would have been more satisfied with your solution.

Since the accepted answer refers to a currently open EE discussion thread,
and to better help me answer future questions, what is the 'solution' to
your question/problem?
blackcat67Author Commented:
since there is no hardware serial for usb sticks there is no exact solution for my question but there may be some solution for copy protection. I decided to write harmless few identifying bytes to boot sector of usb stick and so prevent copying to some degree but this method of course has many disadvantages that I do not have time to mention here. Again thanks to everyone trying to help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.