diskpart and WshScriptExec problem

Discussion in 'Scripting' started by James, Sep 19, 2008.

  1. James

    James Guest


    currently putting together a vbscript that is piping input to diskpart.exe
    (from within winPE). It uses the WshScriptExec object with is sending input
    commands just fine. The problem I'm having is that even know I'm piping the
    'exit' command to diskpart it does not exit... I still see it's process
    running in taskmgr... so my script loops infinitely waiting for that
    WshScriptExec.Status to change from 0, which it doesn't since diskpart does
    not exit. After I manually kill the task with taskmgr, my script breaks out
    of the loop as expected.

    the only command I'm sending diskpart that really takes any time is the
    format command. Thats where my loop comes in and just sleeps waiting for
    that WshScriptExec.status to change, signaling diskpart is done and has
    exited. I would really like to make this work the way I have set out to do
    but I know I have 2 other options: 1, do the format commands outside of
    diskpart with the 'run' instead of the 'exec' method. This would alow for
    running format.com synchronously eliminating the issue of not knowing when
    diskpart is done, or 2, instead of piping the diskpart commands
    interactively I could pipe them to a txt file which could then be supplied
    as script file param to diskpart, again, using run instead of exec so that
    its done synchronously.

    but again, I really like the way I started this... much cooler in my
    opinion, but I need to get this done so if anyone has any ideas as to why
    what I want to do is not working please let me know. I'm going to bail on it
    and move to an alternative by Monday.

    James, Sep 19, 2008
    1. Advertisements

  2. James

    James Guest

    just an update: if someone knows more please do share.

    I've decided to just move the format operations outside of diskpart. My
    hunch is that diskpart's format command is probably just actually calling
    format.com anyway, which is what may be causing my problem with the
    WshScriptExec object.... the program I execute (diskpart.exe) is calling
    another program (format.com) and so the 'wiring' between the program and my
    object get screwy? Thats my hunch, I have to move on. Again, if anyone else
    has any input on this please do share.

    James, Sep 19, 2008
    1. Advertisements

  3. James

    James Guest

    thanks for the input OldDog. The problem though is that I would'nt know
    'when' to kill the process. It runs asynchronously from my main script. I do
    appreciate your response though. Thanks.

    You will probably need to Kill the Diskpart process after you quit.

    ' ProcessKillLocal.vbs
    ' Sample VBScript to kill a program
    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version 2.7 - December 2005
    ' ------------------------ -------------------------------'
    Option Explicit
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strProcessKill
    strComputer = "."
    strProcessKill = "'calc.exe'" <---- Diskpart.exe goes here

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

    Set colProcess = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = " & strProcessKill )
    For Each objProcess in colProcess
    WSCript.Echo "Just killed process " & strProcessKill _
    & " on " & strComputer
    ' End of WMI Example of a Kill Process
    James, Sep 19, 2008
  4. James

    James Guest

    good point, I just double-checked and no, its not awaiting input. Thanks for
    the good thought though.

    When run the same command outside of your script, same values etc. is
    it waiting for any additional input when using diskpart before it hits
    the exit?
    James, Sep 22, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.