HOW TO: Create 2 Equal Size Partitions Regardless of Drive Size

Hey Guys,


Here's some poorly written VBS i put together to create 2 equal size partitions regardless of the hard drive size! I assign the partitions C&Z. I choose Z becuase i noticed D was used by the CD rom and it was causing trouble.


Here's the VBS to create the 2 paritions. Save it as "driver.vbs"



Option Explicit

Dim macer
Dim driveSize
Dim diskpartScript
Dim WshShell

macer = Replace(FindMac(),":","")
driveSize = FindDrive()
diskpartScript =(WriteFile(macer,driveSize))

Set WshShell = WScript.CreateObject("Wscript.Shell")

WshShell.Run "diskpart.exe /s " & diskpartScript,,True

'Find the size of the drive, convert to MB and divide by 2
Function FindDrive()
Dim strComputer
Dim objWMIService
Dim colItems
Dim objItem
Dim strSize

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive",,48)

For Each objItem in colItems
strSize = Int(((objItem.Size/1024)/ 1024) /2)

FindDrive = strSize
End Function

'So hard to find the mac address!!!!!
Function FindMac()
Dim strComputer
Dim objWMIService
Dim colItems
Dim objItem
Dim strAdapterType

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter")

For Each objItem in colItems
Select Case objItem.AdapterTypeID
Case 0 strAdapterType = "Ethernet 802.3"
Case 1 strAdapterType = "Token Ring 802.5"
Case 2 strAdapterType = "Fiber Distributed Data Interface (FDDI)"
Case 3 strAdapterType = "Wide Area Network (WAN)"
Case 4 strAdapterType = "LocalTalk"
Case 5 strAdapterType = "Ethernet using DIX header format"
Case 6 strAdapterType = "ARCNET"
Case 7 strAdapterType = "ARCNET (878.2)"
Case 8 strAdapterType = "ATM"
Case 9 strAdapterType = "Wireless"
Case 10 strAdapterType = "Infrared Wireless"
Case 11 strAdapterType = "Bpc"
Case 12 strAdapterType = "CoWan"
Case 13 strAdapterType = "1394"
End Select
If (objItem.AdapterTypeID = 0 ) Then
FindMac = objItem.MACAddress
End If
End Function

'This creates the text file. We'll use the mac address as the
'name. After we'll use diskpart to create the partitions
Function WriteFile (xMac,xSize)
Dim objFSO
Dim objTextFile
Dim objWMIService
Dim strComputer
Dim colServices
Dim path

Const FOLDER_PATH = "T:\diskparts"

path = FOLDER_PATH & "\" & xMac & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not((objFSO.FolderExists(FOLDER_PATH))) Then objFSO.CreateFolder(FOLDER_PATH)

Set objTextFile = objFSO.OpenTextFile _
(path, FOR_WRITING, True)

objTextFile.writeline "select disk 0"
objTextFile.writeline "clean"
objTextFile.writeline "create partition primary size=" & xSize
objTextFile.writeline "select partition 1"
objTextFile.writeline "active"
objTextFile.writeline "assign letter=c"
objTextFile.writeline "create partition primary"
objTextFile.writeline "select partition 2"
objTextFile.writeline "assign letter=z"
objTextFile.writeline "exit"

WriteFile = path

End Function


I also create a bat Script to Format both the C & Z drive. 



format /q /y /fs:ntfs c:
format /q /y /fs:ntfs z:



Hope this helps.



This post is locked
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ