computerhighguy
IS-IT--Management
I am doing some automation tasks with VBScript and diskpart.exe. I am at a loss for why i cannot get this to work. I am able to use the WScript.Shell EXEC command to execute the commands I need from %COMSPEC% and return it back to a varaible. I can echo that variable using the stdOut.ReadAll method. What I need is to get this in a more usable format. I have been trying to read this information into an array, or something, but can't get it to work. I am using WScript. I could output the contents to a file and read it in one line at a time but ... i figured this was amore realibel method. Any assistance is much appreciated.
Code:
sub DeleteParts()
workDrive = "C:"
dim partExists, counter
Do While partExists <> "No"
dim workDrive, testInfo, diskPartStatus
counter = counter + 1
redim dynVarArray(-1)
Set objShell = CreateObject("WScript.Shell")
set filesys = CreateObject("Scripting.FileSystemObject")
set listFile = filesys.CreateTextFile(workDrive & "\list.txt",True) ' creating the list file to pipe into diskpart.exe
listfile.Write "select disk 0" & vbCRLF & "list partition"
listfile.Close
set listfile = nothing
' Running diskpart.exe to get disk partition information
'set diskPartStatus = objShell.Exec ("%comspec% /c diskpart.exe -s " & workDrive & "\list.txt") ' > " & workDrive & "\results.txt") '%comspec% /c " & workDrive & " &
set diskPartStatus = objShell.Exec ("%comspec% /c type " & workDrive & "\list.txt | diskpart.exe")
'set diskPartStatus = objShell.Exec ("%comspec% /c echo list volume | diskpart.exe")
Wscript.Sleep 1500
wscript.echo cstr(diskPartStatus.StdOut.ReadAll)
'tempStr = cstr(diskPartStatus.StdOut.ReadAll)
'wscript.writeline tempStr
'Set objFile = filesys.OpenTextFile(workDrive & "\results.txt", ForReading)
redim testArray(30)
testArray = Split(tempStr,vbCRLF)
wscript.echo testArray(0)
wscript.echo testArray(1)
wscript.echo testArray(2)
wscript.echo testArray(3)
end sub
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)
Code:
sub DeleteParts()
workDrive = "C:"
dim partExists, counter
Do While partExists <> "No"
dim workDrive, testInfo, diskPartStatus
counter = counter + 1
redim dynVarArray(-1)
Set objShell = CreateObject("WScript.Shell")
set filesys = CreateObject("Scripting.FileSystemObject")
set listFile = filesys.CreateTextFile(workDrive & "\list.txt",True) ' creating the list file to pipe into diskpart.exe
listfile.Write "select disk 0" & vbCRLF & "list partition"
listfile.Close
set listfile = nothing
' Running diskpart.exe to get disk partition information
'set diskPartStatus = objShell.Exec ("%comspec% /c diskpart.exe -s " & workDrive & "\list.txt") ' > " & workDrive & "\results.txt") '%comspec% /c " & workDrive & " &
set diskPartStatus = objShell.Exec ("%comspec% /c type " & workDrive & "\list.txt | diskpart.exe")
'set diskPartStatus = objShell.Exec ("%comspec% /c echo list volume | diskpart.exe")
Wscript.Sleep 1500
wscript.echo cstr(diskPartStatus.StdOut.ReadAll)
'tempStr = cstr(diskPartStatus.StdOut.ReadAll)
'wscript.writeline tempStr
'Set objFile = filesys.OpenTextFile(workDrive & "\results.txt", ForReading)
redim testArray(30)
testArray = Split(tempStr,vbCRLF)
wscript.echo testArray(0)
wscript.echo testArray(1)
wscript.echo testArray(2)
wscript.echo testArray(3)
end sub
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)