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!

At a loss

Status
Not open for further replies.

computerhighguy

IS-IT--Management
Oct 13, 2003
579
US
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)
 
'Set oExec = WshShell.Exec("c:\win\system32\dfsutil.exe /pktinfo")
'blnSectionFound = False
'Do While Not oExec.StdOut.AtEndOfStream
' sLine = LCase(Trim(oExec.StdOut.ReadLine))
''msgbox sLine
' If sLine = "entry: \\dfsroot\software" Then
' blnSectionFound = True
'End If
'If blnSectionFound = True Then
'If Right(sLine, 10) = "( active )" Then
' If InStr(sLine, "[\") > 0 Then
' strDFSServer = Mid(sLine, InStr(sLine, "[\") + 2, Instr(InStr(sLine, "[\") + 2, sLine, "\") - InStr(sLine, "[\") - 2)
' End If
' End If
'End If
'Loop
'Set oExec = Nothing
 
OK. I stumbled upon the solution. Seems that if you put the line

wscript.echo cstr(diskPartStatus.StdOut.ReadAll)

It emptys diskPartStatus

Of course my debugging screwed up the code. I know the above it not complete, but .... it was part of a sub routine.


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