public void AssignDriveLetter() { var inParams = PartitionObject.GetMethodParameters("AddAccessPath"); inParams["AssignDriveLetter"] = true; var outParams = PartitionObject.InvokeMethod("AddAccessPath", inParams, null) !; var code = Convert.ToInt32(outParams["ReturnValue"]); if (code != 0 && code != 42012) { throw new DiskOperationException("Could not assign drive letter", new Win32Exception(code)); } // return code 42012 is ok for some reason, don't ask me why }
public string[] GetAccessPaths() { var inParams = PartitionObject.GetMethodParameters("GetAccessPaths"); var outParams = PartitionObject.InvokeMethod("GetAccessPaths", inParams, null); if (outParams == null) { return(Array.Empty <string>()); } var paths = (string[])outParams["AccessPaths"]; var mappedPaths = paths.Select(p => p.Replace('?', '.')).ToArray(); return(mappedPaths); }