Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A better way to run diskpart.exe ?

Status
Not open for further replies.

computerhighguy

IS-IT--Management
Oct 13, 2003
579
US
OK,
I have created an imaging and archiving system using DriveImage XML, DD for Windows, Bart's PE and Windows Scripting Host. All in all, it is pretty cool and best of all it is free. With a lack of free tools available, I have to resort to using diskpart.exe to create and validate paritions and parition counts. In order to get this to work, I have to call the COMSPEC and run it in a dos window. if it is more than one command, I have to create/open a text file and write the commands to that file and then us it to tell diskpart what to do. Here is an example:

part1Type = "Primary"
part1Size = "size=47"
part1ID = "id=DE" 'Blank for default partition type (06 I believe)
part1Active = " " 'Blank = no, assign = yes
part1Assign = " " 'Blank = no

part2Type = "Primary"
part2Size = ""
part2ID = ""
part2Active = "Active"
part2Assign = "Assign"

Set filesys = CreateObject("Scripting.FileSystemObject")
Set createFile = filesys.CreateTextFile(workDrive & "\create.txt",True)

dim fileContent
fileContent = cleanType & vbCRLF & "select disk 0" & vbCRLF & "create partition " & part1Type & " " & part1Size & " " & part1ID & vbCRLF _
& "create partition " & part2Type & " " & part2Size & " " & part2ID & vbCRLF _
& "select partition 1" & vbCRLF & part1Active & vbCRLF & part1Assign & vbCRLF _
& "select partition 2" & vbCRLF & part2Active & vbCRLF & part2Assign & vbCRLF
' \\ Clean up the commands by removing any blank lines
fileArray = split(fileContent,vbCRLF,-1,1)
for each x in fileArray
if Len(x) > 1 then
newFileContent = newFileContent + x + vbCRLF
end if
next
createfile.Write newFileContent

objShell.Popup "ACSIS COMPUTER IMAGING SYSTEM (CIS)" & vbCRLF & vbCRLF & "Commands to be run:" _
& vbCRLF & newFileContent & vbCRLF & vbCRLF & "Timeout in 10 seconds",10

shResult = objShell.Run ("%comspec% /c " & workDrive & " & echo CREATING PARTITIONS AND WIPING DISK 0 IF SELECTED & diskpart -s create.txt",1,True)



I figure there has to be a better way to do this. All my failures result from diskpart not running properly, completely, etc. Is there a better way I can run diskaprt from within a script to create, delete, etc partitions? All is help is very much appreciated. And by the way, I know my code is not the greatest, but it works (mostly).


It is what it is!!
__________________________________
A+, Net+, I-Net+, Certified Web Master, MCP, MCSA, MCSE, CCNA, CCDA, and few others (I got bored one day)
 
diskpart not running properly, completely
You may try this:
shResult = objShell.Run ("%comspec% /[!]K[/!] " & workDrive & " & echo CREATING PARTITIONS AND WIPING DISK 0 IF SELECTED & diskpart -s create.txt",1,True)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I think there is a misunderstanding here. I am looking for a way of doing this without having to resort to using %COMSPEC%. Shelling it out to a dos window seems to be pretty unreliable.


It is what it is!!
__________________________________
A+, Net+, I-Net+, Certified Web Master, MCP, MCSA, MCSE, CCNA, CCDA, and few others (I got bored one day)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top