-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmountiso.cpp
69 lines (60 loc) · 1.33 KB
/
mountiso.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <initguid.h>
#include <virtdisk.h>
#include <tuple>
#include <cstdio>
#pragma comment(lib, "virtdisk.lib")
int wmain(int argc, wchar_t** argv)
{
if (argc != 2)
{
fwprintf(stderr, L"usage: mountiso <iso>\n");
return 1;
}
VIRTUAL_STORAGE_TYPE storageType{ VIRTUAL_STORAGE_TYPE_DEVICE_ISO , VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT };
HANDLE hDisk;
DWORD ret = OpenVirtualDisk(
&storageType,
argv[1],
VIRTUAL_DISK_ACCESS_ATTACH_RO | VIRTUAL_DISK_ACCESS_DETACH,
OPEN_VIRTUAL_DISK_FLAG_NONE,
NULL,
&hDisk
);
if (ret != ERROR_SUCCESS)
{
fwprintf(stderr, L"OpenVirtualDisk() failed, error %u\n", ret);
return 1;
}
ret = AttachVirtualDisk(
hDisk,
NULL,
ATTACH_VIRTUAL_DISK_FLAG_READ_ONLY,
0,
NULL,
NULL
);
if (ret != ERROR_SUCCESS)
{
fwprintf(stderr, L"AttachVirtualDisk() failed, error %u\n", ret);
CloseHandle(hDisk);
return 1;
}
wprintf(L"ISO mounted: %s\n", argv[1]);
wprintf(L"Press Enter to unmount...");
std::ignore = getwchar();
ret = DetachVirtualDisk(
hDisk,
DETACH_VIRTUAL_DISK_FLAG_NONE,
0
);
if (ret != ERROR_SUCCESS)
{
fwprintf(stderr, L"DetachVirtualDisk() failed, error %u\n", ret);
CloseHandle(hDisk);
return 1;
}
CloseHandle(hDisk);
return 0;
}