Solved

Need to Find Path to CD Rom for System() Command

Posted on 2002-03-05
7
217 Views
Last Modified: 2010-04-01
I am writing an application to be burned on a CD that needs to access other files on the same CD.  For instance, one application on this CD needs to open a .html file also located on the same CD.  For testing purposes, I am using ...

system("index.html");

but this only works with the c: drive.  Obviously, I can also type c:/temp/index.html or whatever the path may be.  However, this application is going to be used on many different computers.  Many computers have the CD as drive d: but also many have it as a drive e: or drive f:. Somehow, I need to find the path to the current user's CD drive and then use that path within the system() command.  NOTE: The system() command uses a const char * as a parameter and I have not been able to figure out how to use a variable instead of a string as shown above.  When I try to use a variable ...
     const char *temp1 = "c:/temp/acrord32.exe";
     system("temp1");
a message tells me that temp1 is not recognized as a internal or external command or operable program.
However, system("c:/temp/acrord32.exe");  works fine.  
Question is:  How do I find the path of the CD ROM and then get that path to work in the system command?  I am assuming that I will need a variable for the path so I can add the path to my application.
0
Comment
Question by:guile1
  • 5
7 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 300 total points
ID: 6843151
You usually would use "GetDriveType()":

char Get1stCDDriveLetter() {

 char c = 'a';
 char acRoot [ MAX_PATH];

 while ( 1){
   sprintf ( acRoot, "%c:\\", c),

   if ( DRIVE_CDROM == GetDriveType ( acRoot)) {
        return ( c);
   }

   c++;
  }

 return 0;
}

This will return the CDROm drive letter...
0
 
LVL 86

Expert Comment

by:jkr
ID: 6843152
Oh, and you would use it like

const char *temp1 = "%c:/temp/acrord32.exe";

char acPath [ MAX_PATH];

sprintf ( acPath, temp1, Get1stCDDriveLetter());

system ( acPath);
0
 
LVL 86

Expert Comment

by:jkr
ID: 6843165
Wait a minute - is your app already started from the CD? If so, it would be easier to use "GetModuleFileName ( NULL)" and use that information...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:jkr
ID: 6843173
Ooops, BTW, make

char c = 'a';

read

char c = 'd';

I think we can safely assume that :o)
0
 

Author Comment

by:guile1
ID: 6843180
Very good!  Thanks.
0
 
LVL 1

Expert Comment

by:jdrescher
ID: 6843823
>Wait a minute - is your app already started from the CD? If so, it would be easier to use "GetModuleFileName
( NULL)" and use that information...

Yes. You better use this instead, because the user may have more than one cdrom drive. My server has three..
0
 
LVL 86

Expert Comment

by:jkr
ID: 6845029
>>because the user may have more than one cdrom drive

That's why the function is named 'Get1stCDDriveLetter()' :o)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now