Verplaatst de CD-/DVD-ROM naar E, maakt een nieuw volume aan met de beschikbare ruimte, geeft deze schijfletter D en formatteerd het volume als NTFS.

HideWindow = 0
WaitOnReturn = True
ForReading = 1
ForWriting = 2
Create = True
FormatASCII = 0
Fixed = 2
 
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
'Voor het verplaatsen van de CD-/DVD-drive:
 
Set objTextStream = objFSO.OpenTextFile("c:\Temp\dpartscript.txt",ForWriting,Create,FormatASCII)
 
objTextStream.WriteLine("list volume")
objTextStream.WriteLine("exit")
objTextStream.Close
 
objWshShell.Run "CMD.EXE /C c:\windows\system32\diskpart.exe /s c:\Temp\dpartscript.txt > c:\temp\vols.txt", HideWindow, WaitOnReturn
 
Set objTextStream = objFSO.OpenTextFile("c:\temp\vols.txt", ForReading)
 
Do While Not objTextStream.AtEndOfStream And Not cdrom = "found" And Not dvdrom = "found"
 
	LineRead = objTextStream.ReadLine
 
	'Instr is case sensitive. Maak daarom van de LineRead string alles lower case.
	If InStr(LCase(LineRead), "cd-rom") > 0 Then
 
		cdrom = "found"
 
	Else If InStr(LCase(LineRead), "dvd-rom") > 0 Then
 
		dvdrom = "found"
 
	     End If
 
	End If
 
Loop
 
objTextStream.Close
 
Set objTextStream = objFSO.OpenTextFile("c:\Temp\dpartscript.txt",ForWriting,Create,FormatASCII)
objTextStream.WriteLine("select " & left(trim(LineRead), 9))
objTextStream.WriteLine("assign letter E")
objTextStream.WriteLine("exit")
objTextStream.Close
 
objWshShell.Run "CMD.EXE /C c:\windows\system32\diskpart.exe /s c:\Temp\dpartscript.txt > C:\temp\mvresult.txt", HideWindow, WaitOnReturn
 
'Voor het aanmaken van de D-schijf:
 
Set objTextStream = objFSO.OpenTextFile("c:\Temp\dpartscript.txt",ForWriting,Create,FormatASCII)
 
objTextStream.WriteLine("select disk 0")
objTextStream.WriteLine("create partition primary")
objTextStream.WriteLine("exit")
objTextStream.Close
 
objWshShell.Run "CMD.EXE /C c:\windows\system32\diskpart.exe /s c:\Temp\dpartscript.txt > c:\temp\partresult.txt", HideWindow, WaitOnReturn
 
Set objTextStream = objFSO.OpenTextFile("c:\Temp\dpartscript.txt",ForWriting,Create,FormatASCII)
 
objTextStream.WriteLine("list volume")
objTextStream.WriteLine("exit")
objTextStream.Close
 
objWshShell.Run "CMD.EXE /C c:\windows\system32\diskpart.exe /s c:\Temp\dpartscript.txt > c:\temp\parts.txt", HideWindow, WaitOnReturn
 
Set objTextStream = objFSO.OpenTextFile("c:\temp\parts.txt", ForReading)
 
Do While Not objTextStream.AtEndOfStream And Not partition = "found"
 
	LineRead = objTextStream.ReadLine
 
	'Instr is case sensitive. Maak daarom van de LineRead string alles lower case.
	If InStr(LCase(LineRead), "partition") > 0 And Not InStr(LCase(LineRead), "ntfs") > 0 And Not InStr(LCase(LineRead), "fat32") > 0 And Not InStr(LCase(LineRead), "fat") > 0 Then
 
		partition = "found"
 
	End If
 
Loop
 
objTextStream.Close
 
If partition = "found" Then
 
	Set objTextStream = objFSO.OpenTextFile("c:\Temp\dpartscript.txt",ForWriting,Create,FormatASCII)
	objTextStream.WriteLine("select " & left(trim(LineRead), 9))
	objTextStream.WriteLine("assign letter D")
	objTextStream.WriteLine("exit")
	objTextStream.Close	
 
	objWshShell.Run "CMD.EXE /C c:\windows\system32\diskpart.exe /s c:\Temp\dpartscript.txt > c:\temp\mvpartresult.txt", HideWindow, WaitOnReturn
 
End If
 
'Voer een quick format van de D-schijf uit als dit een fixed disk is.
If objFSO.DriveExists("D:") Then
 
	Set drive = objFSO.GetDrive("D:")
 
	If drive.DriveType = Fixed Then
 
		objWshShell.Run "CMD /C c:\windows\system32\format.com D: /fs:ntfs /q /y > c:\temp\dformat.txt", HideWindow, WaitOnReturn
 
	End If
 
End If
 
Set objTextStream = Nothing
Set objFSO = Nothing
Set objWshShell = Nothing

Bronnen:Microsoft Windows Vista TechCenter - DiskPart Command-Line Options, Microsoft Support - A Description of the Diskpart Command-Line Utility