• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

Was .exe file executed from cd -rom or from a hard drive!?

How to programatically find out if .exe (VC++6.00) file executed from cd-rom or from a hard drive
  • 2
  • 2
1 Solution
AndyAinscowFreelance programmer / ConsultantCommented:
GetModuleFileName should tell you the complete path and file name of the running app INCLUDING the drive.
GetDriveType will allow you to identify what type of drive eg. CD-rom
khlausterAuthor Commented:
I'll try and let you know if it worked out well with me
khlausterAuthor Commented:
Hi, AndyAinscow!

I used GetCurrentDir instead of  GetModuleFileName and,
it looks like it works well after a few simple tests.
Please, glance at my code and let me know if it is a right
way to prevent executing application right from CD.

char currentDir[MAX_PATH];
unsigned int DriveType = GetDriveType(currentDir);
if(DriveType == 1)
      AfxMessageBox("Hard drive! Continue to run application!");
      }else if(DriveType > 1)
AfxMessageBox("You must install this application on your hard !");      
return 0;            
In any event , 100 points is yours

Thanks again
AndyAinscowFreelance programmer / ConsultantCommented:
You cannot guarantee that the current directory is the directory your app started from.  (In most cases it is but it is safer to use the GetModuleFileName).
Otherwise it should be suitable.
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.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now