Solved

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

Posted on 2002-03-05
7
216 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

746 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

12 Experts available now in Live!

Get 1:1 Help Now