示例#1
0
        public void Online()
        {
            var result = (string?)PartitionObject.InvokeMethod("Online", Array.Empty <object>());

            if (result != null)
            {
                throw new DiskOperationException(result);
            }
        }
示例#2
0
        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
        }
示例#3
0
        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);
        }