HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
Go Back  Xtreme Visual Basic Talk > > > HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?


Reply
 
Thread Tools Display Modes
  #1  
Old 12-22-2016, 12:35 PM
yossi321 yossi321 is offline
Freshman
 
Join Date: Sep 2009
Posts: 28
Default HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?


HELLO
I WANT TO OPEN VHD FILE VIA OpenVirtualDisk
I DID NOT FIND ANY VB6 CODE
ANY HELP PLEASE?
Reply With Quote
  #2  
Old 12-24-2016, 10:28 AM
yossi321 yossi321 is offline
Freshman
 
Join Date: Sep 2009
Posts: 28
Default

I TRIED THIS
Code:
Private Declare Function OpenVirtualDisk Lib "VirtDisk" (ByRef VirtualStorageType As PVirtualStorageType, ByVal Path As String, ByVal VirtualDiskAccessMask As Long, ByVal Flags As Long, ByVal Parameters As Long, ByVal Handle As Long) As Long
Private Type GUID
 Data1 As Long
 Data2 As Integer
 Data3 As Integer
 Data4(7) As Byte
End Type
Private Type PVirtualStorageType
   DeviceId As Long
   VendorId As GUID
End Type
Const VIRTUAL_STORAGE_TYPE_DEVICE_UNKNOWN = 0
Const VIRTUAL_STORAGE_TYPE_DEVICE_ISO = 1
Const VIRTUAL_STORAGE_TYPE_DEVICE_VHD = 2
Const VIRTUAL_STORAGE_TYPE_DEVICE_VHDX = 3

  Const VIRTUAL_DISK_ACCESS_NONE = &H0
  Const VIRTUAL_DISK_ACCESS_ATTACH_RO = &H10000
  Const VIRTUAL_DISK_ACCESS_ATTACH_RW = &H20000
  Const VIRTUAL_DISK_ACCESS_DETACH = &H40000
  Const VIRTUAL_DISK_ACCESS_GET_INFO = &H80000
  Const VIRTUAL_DISK_ACCESS_CREATE = &H100000
  Const VIRTUAL_DISK_ACCESS_METAOPS = &H200000
  Const VIRTUAL_DISK_ACCESS_READ = &HD0000
  Const VIRTUAL_DISK_ACCESS_ALL = &H3F0000
  Const VIRTUAL_DISK_ACCESS_WRITABLE = &H320000
  
   Const OPEN_VIRTUAL_DISK_FLAG_NONE = &H0
  Const OPEN_VIRTUAL_DISK_FLAG_NO_PARENTS = &H1
  Const OPEN_VIRTUAL_DISK_FLAG_BLANK_FILE = &H2
  Const OPEN_VIRTUAL_DISK_FLAG_BOOT_DRIVE = &H4
  Const OPEN_VIRTUAL_DISK_FLAG_CACHED_IO = &H8
  Const OPEN_VIRTUAL_DISK_FLAG_CUSTOM_DIFF_CHAIN = &H10
Private Sub Form_Load()
Dim vst As PVirtualStorageType, hnd As Long
vst.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_VHD
w = OpenVirtualDisk(vst, "E:\1.vhd", VIRTUAL_DISK_ACCESS_ATTACH_RW, OPEN_VIRTUAL_DISK_FLAG_CACHED_IO, 0&, hnd)
BUT I GOT ERROR 87 ERROR_INVALID_PARAMETER

ANY HELP PLEASE?
Reply With Quote
  #3  
Old 01-16-2017, 04:35 AM
fafalone fafalone is offline
Freshman
 
Join Date: May 2010
Posts: 37
Default

Well the last parameter should be ByRef

But I was recently playing around with it myself, and it's a really finicky function.

OPEN_VIRTUAL_DISK_FLAG_CACHED_IO was giving me error 87; changing it to OPEN_VIRTUAL_DISK_FLAG_NONE however I got the function to work.

Also had problems with the access mask after that. Requesting ATTACH_RW resulting in an 'open in another process' error 20, but VIRTUAL_DISK_ACCESS_ALL was allowed.

Here's what I used to open a test vhd created moments ago in the Disk Management panel:

First, fixed/improved declares:
Code:
Public Declare Function OpenVirtualDisk Lib "VirtDisk" (VirtualStorageType As VIRTUAL_STORAGE_TYPE, _
        ByVal Path As Long, ByVal VirtualDiskAccessMask As VIRTUAL_DISK_ACCESS_MASK, ByVal Flags As OPEN_VIRTUAL_DISK_FLAG, ByVal Parameters As Long, Handle As Long) As Long

Public Type VIRTUAL_STORAGE_TYPE
   DeviceId As VirtualStorageDeviceType
   VendorId As GUID
End Type
Public Enum VirtualStorageDeviceType
    VIRTUAL_STORAGE_TYPE_DEVICE_UNKNOWN = 0
    VIRTUAL_STORAGE_TYPE_DEVICE_ISO = 1
    VIRTUAL_STORAGE_TYPE_DEVICE_VHD = 2
    VIRTUAL_STORAGE_TYPE_DEVICE_VHDX = 3
End Enum
Public Enum VIRTUAL_DISK_ACCESS_MASK
    VIRTUAL_DISK_ACCESS_NONE = &H0
    VIRTUAL_DISK_ACCESS_ATTACH_RO = &H10000
    VIRTUAL_DISK_ACCESS_ATTACH_RW = &H20000
    VIRTUAL_DISK_ACCESS_DETACH = &H40000
    VIRTUAL_DISK_ACCESS_GET_INFO = &H80000
    VIRTUAL_DISK_ACCESS_CREATE = &H100000
    VIRTUAL_DISK_ACCESS_METAOPS = &H200000
    VIRTUAL_DISK_ACCESS_READ = &HD0000
    VIRTUAL_DISK_ACCESS_ALL = &H3F0000
    VIRTUAL_DISK_ACCESS_WRITABLE = &H320000
End Enum
Public Enum OPEN_VIRTUAL_DISK_FLAG
    OPEN_VIRTUAL_DISK_FLAG_NONE = &H0
    OPEN_VIRTUAL_DISK_FLAG_NO_PARENTS = &H1
    OPEN_VIRTUAL_DISK_FLAG_BLANK_FILE = &H2
    OPEN_VIRTUAL_DISK_FLAG_BOOT_DRIVE = &H4
    OPEN_VIRTUAL_DISK_FLAG_CACHED_IO = &H8
    OPEN_VIRTUAL_DISK_FLAG_CUSTOM_DIFF_CHAIN = &H10
End Enum
Then
Code:
Private Sub Command8_Click()
Dim tVST As VIRTUAL_STORAGE_TYPE
Dim hVHD As Long
Dim vhdhr As Long
tVST.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_VHD

'VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT
Call DEFINE_GUID(tVST.VendorId, &HEC984AEC, CInt(&HA0F9), CInt(&H47E9), &H90, &H1F, &H71, &H41, &H5A, &H66, &H34, &H5B)

vhdhr = OpenVirtualDisk(tVST, StrPtr("C:\util\test.vhd"), VIRTUAL_DISK_ACCESS_ALL, OPEN_VIRTUAL_DISK_FLAG_NONE, 0&, hVHD)

Debug.Print "vhd hr=0x" & Hex$(vhdhr)
MsgBox "h=" & hVHD

CloseHandle hnd
Exit Sub

Public Sub DEFINE_GUID(Name As GUID, L As Long, w1 As Integer, w2 As Integer, B0 As Byte, b1 As Byte, b2 As Byte, B3 As Byte, b4 As Byte, b5 As Byte, b6 As Byte, b7 As Byte)
  With Name
    .Data1 = L
    .Data2 = w1
    .Data3 = w2
    .Data4(0) = B0
    .Data4(1) = b1
    .Data4(2) = b2
    .Data4(3) = B3
    .Data4(4) = b4
    .Data4(5) = b5
    .Data4(6) = b6
    .Data4(7) = b7
  End With
End Sub
Reply With Quote
Reply

Tags
code, file, openvirtualdisk, vb6, vhd, api


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API? HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
 
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
HOW TO OPEN VHD FILE VIA OpenVirtualDisk API?
 
-->