-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathMountWIM.vbs
More file actions
162 lines (127 loc) · 4.66 KB
/
MountWIM.vbs
File metadata and controls
162 lines (127 loc) · 4.66 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
'*******************************************************************************
' Program: MountWIM.vbs
' Author: Mick Pletcher
' Date: 19 February 2010
' Modified:
'
' Description: This script will mount a WIM file. It will display a list of
' WIM files and allow the user to select which one to mount.
' 1) Define Relative Path
' 2) Select the WIM file
' 3) Mount the WIM file
' 4) Cleanup Global Variables
'*******************************************************************************
Option Explicit
REM Define Global Variables
DIM strImageName : Set strImageName = Nothing
DIM RelativePath : Set RelativePath = Nothing
DefineRelativePath()
SelectImage()
MountWIM()
ImageMounted()
GlobalVariableCleanup()
'*******************************************************************************
'*******************************************************************************
Sub DefineRelativePath()
REM Get File Name with full relative path
RelativePath = WScript.ScriptFullName
REM Remove file name, leaving relative path only
RelativePath = Left(RelativePath, InStrRev(RelativePath, "\"))
End Sub
'*******************************************************************************
Sub SelectImage()
REM Define Local Constants
CONST ForAppending = 2
REM Define Objects
DIM strComputer : strComputer = "."
DIM objWMIService : Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
DIM colFileList : Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name=" & Chr(39) & Left(RelativePath, Len(RelativePath)-1) & Chr(39) & "} Where " _
& "ResultClass = CIM_DataFile")
DIM objFile : Set ObjFile = Nothing
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
REM Define Local Variables
DIM Count : Count = 1
DIM FileName : Set FileName = Nothing
DIM FileVerify : Set FileVerify = Nothing
DIM strList : strList = "Select an Image File:"
REM Get List of WIM files
For Each objFile In colFileList
FileVerify = Right(objFile.Name, 3)
If FileVerify = "wim" then
FileName = Len(objFile.Name)
FileName = FileName - 9
FileName = Right(objFile.Name, FileName)
strList = strList & vbCrLf & Count & " - " & FileName
Count = Count + 1
End If
Set FileVerify = Nothing
Next
REM Select WIM File
strImageName = InputBox(strList, "Image")
strImageName = CInt(strImageName)
REM ReInitialize Variables
Count = 1
Set FileName = Nothing
Set FileVerify = Nothing
Set objFile = Nothing
REM Get File Name
For Each objFile In colFileList
FileVerify = Right(objFile.Name, 3)
If FileVerify = "wim" then
FileName = Len(objFile.Name)
FileName = FileName - 9
FileName = Right(objFile.Name, FileName)
If Count = strImageName then
strImageName = FileName
End If
Count = Count + 1
End If
Set FileVerify = Nothing
Next
REM Cleanup Local Variables
Set colFileList = Nothing
Set Count = Nothing
Set FileName = Nothing
Set FileVerify = Nothing
Set strComputer = Nothing
Set objFile = Nothing
Set FSO = Nothing
Set objWMIService = Nothing
Set strList = Nothing
End Sub
'*******************************************************************************
Sub MountWIM()
REM Define Local Objects
DIM oShell : SET oShell = CreateObject("Wscript.Shell")
REM Define Local Variables
DIM WIMFile : WIMFile = Chr(32) & "/wimfile:" & RelativePath & strImageName
DIM Index : Index = Chr(32) & "/index:1"
DIM MountDIR : MountDIR = Chr(32) & "/mountdir:" & RelativePath & "mount"
DIM MountFile : MountFile = "DISM.exe /mount-wim" & WIMFile & Index & MountDIR
oShell.Run MountFile, 1, True
REM Cleanup Local Variables
Set Index = Nothing
Set MountDIR = Nothing
Set MountFile = Nothing
Set oShell = Nothing
Set WIMFile = Nothing
End Sub
'*******************************************************************************
Sub ImageMounted()
REM Define Local Objects
DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(RelativePath & "Mount\Windows") Then
MsgBox(strImageName & Chr(32) & "is mounted")
Else
MsgBox(strImageName & Chr(32) & "failed to mount")
End If
REM Cleanup Local Objects
Set FSO = Nothing
End Sub
'*******************************************************************************
Sub GlobalVariableCleanup()
Set RelativePath = Nothing
Set strImageName = Nothing
End Sub