zackiv31 Posted August 9, 2007 Share Posted August 9, 2007 Is there a built in function to get the location (drive letter) of the windows drive? Is the best way to do this just to check for the boot.ini? Was just wondering if there is a more definitive way. Link to comment Share on other sites More sharing options...
0 Antaris Veteran Posted August 9, 2007 Veteran Share Posted August 9, 2007 You can use the GetWindowsDirectory(...) API call and then get the drive letter from that: public static class WinAPI { [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern uint GetWindowsDirectory(StringBuilder lpBuffer, uint uSize); public static string WindowsDirectory { get { StringBuilder builder = new StringBuilder(255); int length = (int)GetWindowsDirectory(builder, 255); return builder.ToString(0, length).ToLower(); } } public static string WindowsDrive { get { return WindowsDirectory.Substring(0,1); } } } Link to comment Share on other sites More sharing options...
0 +Biscuits Brown MVC Posted August 9, 2007 MVC Share Posted August 9, 2007 An easier way that uses the framework Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0,1) This returns the path to drive:\\Windows\System32 folder so you just pull off the drive letter from the left. Link to comment Share on other sites More sharing options...
Question
zackiv31
Is there a built in function to get the location (drive letter) of the windows drive?
Is the best way to do this just to check for the boot.ini? Was just wondering if there is a more definitive way.
Link to comment
Share on other sites
2 answers to this question
Recommended Posts