Global $A4A, $A4B, $A4C, $A4D, $A4E, $A4F
Global $A49[16][55535 + 2 + 1]
_3S_()
Func _3S_()
If @OSBuild < 6500 Then
MsgBox(32, 'oops', 'Sorry VHD Features are only available in Windows 7.')
Exit
EndIf
Local $AM6, $AM7
$AM6 = GUICreate('Create, Attach and Detach Virtual Hard Disk', 400, 200)
GUISetIcon(@ScriptFullPath, 207)
$A4A = _42_($AM6, 'Create', 10, 10, 350, 50, 14)
$A4B = _42_($AM6, 'Attach', 10, 60, 350, 50, 14)
$A4C = _42_($AM6, 'Detach', 10, 110, 350, 50, 14)
_43_($A4A, 'Create a partitioned VHD ready for setup')
_43_($A4B, 'Attach a existing VHD to system')
_43_($A4C, 'Detach a attached VHD from system')
$AM7 = GUICtrlCreateLabel('', 10, 150, 0, 0)
GUIRegisterMsg(273, '_3t_')
GUISetState()
ControlFocus($AM6, '', $AM7)
While 1
Switch GUIGetMsg()
Case -3
ExitLoop
EndSwitch
If $A4D Or $A4E Or $A4F = 1 Then ExitLoop
WEnd
If $A4D = 1 Then
GUIDelete($AM6)
_3U_()
ElseIf $A4E = 1 Then
GUIDelete($AM6)
_3W_()
ElseIf $A4F = 1 Then
GUIDelete($AM6)
_3V_()
EndIf
Exit
EndFunc ;==>_3S_
Func _3T_($AIA, $AIV, $AIC, $AID)
#forceref $aia, $aiv
Local $AM8 = BitShift($AIC, 16)
Local $AM9 = BitAND($AIC, 65535)
Local $AMA = $AID
Local $ADE = ''
Switch $AMA
Case $A4A
Switch $AM8
Case 0
$A4D = 1
EndSwitch
Case $A4B
Switch $AM8
Case 0
$A4E = 1
EndSwitch
Case $A4C
Switch $AM8
Case 0
$A4F = 1
EndSwitch
EndSwitch
Return 'GUI_RUNDEFMSG'
EndFunc ;==>_3T_
Func _3U_()
$AMB = GUICreate('Create and Attach Virtual Hard Disk', 380, 340)
GUISetState($AMB)
GUISetIcon(@ScriptFullPath, 207)
GUISetState()
GUICtrlCreateLabel('Specify the virtual hard disk location on the machine.', 10, 10)
GUICtrlCreateLabel('&Location:', 10, 40)
$AMC = GUICtrlCreateInput('', 10, 60, 275)
$AMD = GUICtrlCreateButton('&Browse...', 295, 58, 80)
GUICtrlCreateLabel('Virtual hard disk &size:', 10, 100)
$AME = GUICtrlCreateInput('25', 240, 100, 80)
$AMF = GUICtrlCreateCombo('MB', 327, 100, 42, -1, 3)
GUICtrlSetData(-1, 'GB', 'GB')
GUICtrlCreateGroup('Virtual hard disk format', 10, 130, 360, 163)
$AMG = GUICtrlCreateRadio('&Dynamically expanding', 30, 145, 200, 20)
GUICtrlCreateLabel('The size of this virtual hard disk expands to a fixed maximum size as data is saved to it. The disk size does not compact automatically when data is deleted.', 30, 165, 330, 50)
$AMH = GUICtrlCreateRadio('&Fixed size (Recommended)', 30, 210, 200, 20)
GUICtrlCreateLabel('The virtual hard disk uses a fixed amount of space regardless of the amount of the data stored on it. Its default size is the maximum amount of space available on your physical hard disk.', 30, 230, 330, 50)
GUICtrlSetState($AMH, 1)
$AMI = GUICtrlCreateButton('Cancel', 290, 310, 80)
$AMJ = GUICtrlCreateButton('OK', 205, 310, 80)
While 1
Sleep(10)
$AIV = GUIGetMsg()
Switch $AIV
Case -3, $AMI
GUIDelete($AMB)
Return
Case $AMD
Local $ADY = FileSaveDialog('Choose a name for the new Vdisk file', '', 'Virtual Hard Disk (*.vhd)', 18, 'Windows7.vhd')
If Not @error Then GUICtrlSetData($AMC, $ADY)
Case $AMJ
$AMK = GUICtrlRead($AMC)
$AML = GUICtrlRead($AME)
$AMM = ''
$AMN = 'Win7 VHD'
If Not StringMid($AMK, 2, 1) = ':' Then
MsgBox(48, 'Error', 'No VHD file location selected.')
ContinueCase
EndIf
If StringRegExp($AML, '[^0-9]') Or StringLen($AML) = 0 Then
MsgBox(48, 'Error', 'Invalid Size type, please use only digets')
ContinueCase
EndIf
$AMO = GUICtrlRead($AMF)
If $AMO = 'GB' Then
$AML = $AML * 1024
EndIf
$AMP = 'expandable'
If BitAND(GUICtrlRead($AMH), 1) Then $AMP = 'fixed'
$AED = DriveGetDrive('all')
$AHO = 'z:'
For $AE1 = Asc('d') To Asc('z')
$AMQ = 0
For $A79 = 1 To $AED[0]
IF (Chr($AE1) & ':') = $AED[$A79] Then $AMQ = 1
Next
If $AMQ = 0 Then
$AHO = Chr($AE1) & ':'
ExitLoop
EndIf
Next
GUIDelete($AMB)
_3X_($AMK, $AML, $AMP, $AHO, $AMN)
Return
EndSwitch
WEnd
EndFunc ;==>_3U_
Func _3V_()
Local $ADY = FileOpenDialog('Select Vdisk file to detach', '', 'Virtual Hard Disk (*.vhd)')
If @error Then Exit
Local $AMR = @TempDir & '\' & Random(1000, 9999, 1) & '_diskpart.txt'
$AIJ = FileOpen($AMR, 2)
FileWrite($AIJ, 'select vdisk file="' & $ADY & '"' & @CRLF & 'detach vdisk' & @CRLF)
FileClose($AIJ)
$A52 = ShellExecuteWait('diskpart.exe', '/s "' & $AMR & '"')
If $A52 = 0 Then
MsgBox(64, 'Finshed VHD', 'VHD file: ' & $ADY & ' was successfully detach')
FileDelete($AMR)
Return
Else
MsgBox(16, 'Failed to detach VHD', 'An error (' & $A52 & ') occured during VHD detached')
FileDelete($AMR)
Return
EndIf
EndFunc ;==>_3V_
Func _3W_()
Local $ADY = FileOpenDialog('Select Vdisk file to attach', '', 'Virtual Hard Disk (*.vhd)')
If @error Then Exit
Local $AMR = @TempDir & '\' & Random(1000, 9999, 1) & '_diskpart.txt'
$AIJ = FileOpen($AMR, 2)
FileWrite($AIJ, 'select vdisk file="' & $ADY & '"' & @CRLF & 'attach vdisk' & @CRLF)
FileClose($AIJ)
$A52 = ShellExecuteWait('diskpart.exe', '/s "' & $AMR & '"')
If $A52 = 0 Then
MsgBox(64, 'Finshed VHD', 'VHD file: ' & $ADY & ' was successfully attached')
FileDelete($AMR)
Return
Else
MsgBox(16, 'Failed to attach VHD', 'An error (' & $A52 & ') occured during VHD attached')
FileDelete($AMR)
Return
EndIf
EndFunc ;==>_3W_
Func _3X_($AMK, $AML, $AMP, $AHO, $AMN)
Local $AMR = @TempDir & '\' & Random(1000, 9999, 1) & '_diskpart.txt'
$AIJ = FileOpen($AMR, 2)
FileWrite($AIJ, 'create vdisk file="' & $AMK & '" maximum=' & $AML & ' type=' & $AMP & @CRLF & 'select vdisk file="' & $AMK & '"' & @CRLF & 'attach vdisk' & @CRLF & 'create partition primary' & @CRLF & 'format quick label="' & $AMN & '"' & @CRLF & 'assign letter=' & $AHO & @CRLF)
FileClose($AIJ)
$A52 = ShellExecuteWait('diskpart.exe', '/s "' & $AMR & '"')
If $A52 = 0 Then
MsgBox(64, 'Finshed VHD', 'VHD file: ' & $AMK & ' was successfully created.')
FileDelete($AMR)
Return
Else
MsgBox(16, 'Failed to create VHD', 'An error (' & $A52 & ') occured during VHD creation.')
FileDelete($AMR)
Return
EndIf
EndFunc
Func _40_($ADE, $AN3 = 0, $AN4 = 0, $AN5 = False)
Local $AN6 = 'ptr', $AN7 = $ADE
If IsDllStruct($ADE) Then
$AN7 = DllStructGetPtr($ADE)
Else
If Not IsPtr($ADE) Then $AN6 = 'STR'
EndIf
Local $A8D = DllCall('kernel32.dll', 'int', 'MultiByteToWideChar', 'uint', $AN3, 'dword', $AN4, $AN6, $AN7, 'int', -1, 'ptr', 0, 'int', 0)
If @error Then Return SetError(@error, @extended, 0)
Local $AN8 = $A8D[0]
Local $A84 = DllStructCreate('wchar[' & $AN8 & ']')
Local $AN9 = DllStructGetPtr($A84)
$A8D = DllCall('kernel32.dll', 'int', 'MultiByteToWideChar', 'uint', $AN3, 'dword', $AN4, $AN6, $AN7, 'int', -1, 'ptr', $AN9, 'int', $AN8)
If @error Then Return SetError(@error, @extended, 0)
If $AN5 Then Return DllStructGetData($A84, 1)
Return $A84
EndFunc ;==>_40_
Func _41_($AIA)
Local $ANA, $ANB = -1, $ANC = True
If Not WinExists($AIA) Then Return SetError(-1, -1, 0)
For $AND = 0 To 16 - 1
If $A49[$AND][0] <> 0 Then
If Not WinExists($A49[$AND][0]) Then
For $A4H = 0 To UBound($A49, 2) - 1
$A49[$AND][$A4H] = 0
Next
$A49[$AND][1] = 10000
$ANC = False
EndIf
EndIf
Next
For $AND = 0 To 16 - 1
If $A49[$AND][0] = $AIA Then
$ANB = $AND
ExitLoop
EndIf
Next
If $ANB = -1 Then
For $AND = 0 To 16 - 1
If $A49[$AND][0] = 0 Then
$A49[$AND][0] = $AIA
$A49[$AND][1] = 10000
$ANC = False
$ANB = $AND
ExitLoop
EndIf
Next
EndIf
If $ANB = -1 And $ANC Then Return SetError(16, 0, 0)
If $A49[$ANB][1] = 10000 + 55535 Then
For $ANE = 2 To UBound($A49, 2) - 1
If $A49[$ANB][$ANE] = 0 Then
$ANA = ($ANE - 2) + 10000
$A49[$ANB][$ANE] = $ANA
Return $ANA
EndIf
Next
Return SetError(-1, 55535, 0)
EndIf
$ANA = $A49[$ANB][1]
$A49[$ANB][1] += 1
$A49[$ANB][($ANA - 10000) + 2] = $ANA
Return $ANA
EndFunc ;==>_41_
Func _42_($AIA, $ADE, $AMW, $AMX, $AD9, $ADA, $AMV = -1, $AMS = -1)
If Not IsHWnd($AIA) Then
Return SetError(1, 0, 0)
EndIf
If Not IsString($ADE) Then
Return SetError(2, 0, 0)
EndIf
Local $ANF = BitOR(65536, 268435456, 1073741824, 16384)
If $AMV = -1 Then
$AMV = $ANF
Else
$AMV = BitOR($AMV, $ANF)
EndIf
If $AMS = -1 Then $AMS = 0
Local $ANA = _41_($AIA)
If @error Then Return SetError(@error, @extended, 0)
Local $ANG = _3Y_($AMS, 'Button', $ADE, $AMV, $AMW, $AMX, $AD9, $ADA, $AIA, $ANA)
_2G_($ANG, 48, _3__(17), True)
Return $ANG
EndFunc ;==>_42_
Func _43_($AIA, $ANH)
If Not IsHWnd($AIA) Then $AIA = GUICtrlGetHandle($AIA)
Local $ANI = _40_($ANH)
Return _2G_($AIA, 5641, 0, DllStructGetPtr($ANI)) <> 0
EndFunc ;==>_43_
Func _3Y_($AMS, $AMT, $AMU, $AMV, $AMW, $AMX, $AD9, $ADA, $AMY, $AMZ = 0, $A7Q = 0, $AM_ = 0)
If $A7Q = 0 Then $A7Q = _3Z_('')
Local $A8D = DllCall('user32.dll', 'hwnd', 'CreateWindowExW', 'dword', $AMS, 'wstr', $AMT, 'wstr', $AMU, 'dword', $AMV, 'int', $AMW, 'int', $AMX, 'int', $AD9, 'int', $ADA, 'hwnd', $AMY, 'handle', $AMZ, 'handle', $A7Q, 'ptr', $AM_)
If @error Then Return SetError(@error, @extended, 0)
Return $A8D[0]
EndFunc ;==>_3Y_
Func _2G_($AIA, $AIB, $AIC = 0, $AID = 0, $AIE = 0, $AIF = 'wparam', $AIG = 'lparam', $AIH = 'lparam')
Local $A8D = DllCall('user32.dll', $AIH, 'SendMessage', 'hwnd', $AIA, 'int', $AIB, $AIF, $AIC, $AIG, $AID)
If @error Then Return SetError(@error, @extended, '')
If $AIE >= 0 And $AIE <= 4 Then Return $A8D[$AIE]
Return $A8D
EndFunc ;==>_2G_
Func _3__($AN2)
Local $A8D = DllCall('gdi32.dll', 'handle', 'GetStockObject', 'int', $AN2)
If @error Then Return SetError(@error, @extended, 0)
Return $A8D[0]
EndFunc ;==>_3__
Func _3Z_($AN0)
Local $AN1 = 'wstr'
If $AN0 = '' Then
$AN0 = 0
$AN1 = 'ptr'
EndIf
Local $A8D = DllCall('kernel32.dll', 'handle', 'GetModuleHandleW', $AN1, $AN0)
If @error Then Return SetError(@error, @extended, 0)
Return $A8D[0]
EndFunc