I want to create a file in (drive letter):\Program Files\myprog\file.ext where (drive letter) is the drive letter where windows is installed (or the default drive). Is there an easy Windows API method to retrieve it?

Thanks

PS, here is what I'm currently using:

string mainDrive = "";
      foreach (string drive in Directory.GetLogicalDrives())
      {
        Console.WriteLine(drive);
        if (Directory.Exists(drive + "WINDOWS\\System32") || Directory.Exists(drive + "WINDOWS NT\\System32"))
        {
          mainDrive = drive;
          break;
        }
      }
      if (mainDrive.Equals(""))
      {
        // couldn't find default directory, should probably do some error checking
        mainDrive = "C:\\";
      }

Recommended Answers

All 2 Replies

I believe you can use "%programfiles%" and it should result in the path [Default drive letter]:\Program Files\.

Edit: If not you can use "%SystemDrive%\\Program Files\\" .

that worked, thanks a lot! Had to use Environment.GetSystemVariable("%SystemDrive%")

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.