hi guys and girls if any :P, im trying to find out how to determine the root directory of a computer, in c++ as part of a larger program im working on, im sure i heard before that there is some api call that can be used to do this, i fi have explained it wrong here is an example:

C:\Program files\Program\Program.exe

I am looking how to automatically find out the root drive (C:\) of a computer.
Does anyone have any ideas ?

do you want the drive letter of the drive on which the os is installed? such as "c:"? or the path that the program is starting from? argv[0] or win3w2 api function GetModuleFileName() will give you the latter.

i want to find the drive the OS is on yea, I have used GetModuleFileName() function before. But it only returns the location of the program. If argv[0] is what i need, can you give me an example of how you use it ?
Thanks..

argv[0] will give you the same as GetModuleFileName(). XP has windir environment variable. Earlier os may be different -- check your PATH environment variable.

char* path = getenv("windir");

I'm supprised the return pointer from getenv() is not const because you can't modifiy its value.

thanks alot guys, helped a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.