示例#1
0
        public int AttachDisk(IntPtr Handle)
        {
            try
            {
                var Parameters = new ATTACH_PARAMETERS();
                Parameters.Version = ATTACH_VERSION.VERSION_1;
                int Result = AttachVirtualDisk(Handle, IntPtr.Zero, ATTACH_FLAG.PERMANENT_LIFETIME, 0, ref Parameters, IntPtr.Zero);

                if (Result == 0)
                {
                    return(1);
                }

                if (Result != 0)
                {
                    return(0);

                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Error {0}.", Result));
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}\n{1}", e.Message, e.StackTrace);
                return(0);
            }

            CloseHandle(Handle);
            return(0);
        }
示例#2
0
        public static void AttachDisk(IntPtr Handle, bool RO)
        {
            try
            {
                var Parameters = new ATTACH_PARAMETERS();
                Parameters.Version = ATTACH_VERSION.VERSION_1;

                var Flag = RO ? ATTACH_FLAG.PERMANENT_LIFETIME | ATTACH_FLAG.READ_ONLY : ATTACH_FLAG.PERMANENT_LIFETIME;

                int Result = AttachVirtualDisk(Handle, IntPtr.Zero, Flag, 0, ref Parameters, IntPtr.Zero);
                if (Result != 0)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Error {0}.", Result));
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}\n{1}", e.Message, e.StackTrace);
            }

            CloseHandle(Handle);
        }
示例#3
0
 public static extern Int32 AttachVirtualDisk(IntPtr Handle, IntPtr SecurityDescriptor, ATTACH_FLAG Flag, Int32 ProviderSpecificFlags, ref ATTACH_PARAMETERS Parameters, IntPtr Overlapped);