locked
batch scripting in WinPe environment RRS feed

  • Question

  • Hello,

    I currently have a custom install disc that we use here at my job. It first opens in a WinPE environment. I have a .cmd script that then runs to begin partitioning the hard drive (does this using diskpart). I would like to modify this script to get the size of the hard drive (disk 0) before actually doing the partitioning. I need to do this because the hdd may be different sizes depending on the machine , therefore if it is a bigger size the partitions will be bigger.

     I tried running chkdsk on the %systemdrive% to get the total disk size but that actually gave me the size of the temp ram on which the winpe environment resides. Any help on how to do this would be appreciated

     

     

    Tuesday, December 27, 2011 3:44 PM

Answers

  • You may have the WMIC.EXE command in your PE environment already. If so, you can use it to query WMI.


    Rob - YOu have to specifically select to add WMI support to get WMIC.

    Yes- WMIC is very easy to use in a batch script.  Unfortuanley I do not believe it is available for WinPE.

    I also discovered that you have to add WSH support specifically in order to use the WMI provider.

    Here is the list of WnPE packages through WS2008R2.

    THe OP could just create a simple scipt to return disk size but you would have to first partition the disk at full size.  You cannot read a raw disk with WMI.  Diskpart can read a raw disk but it is a bit difficult to get the size but it can be done.

    Diskpart cancreate a partition th efull size of teh drive and then listing the partitoin will give its size.  You can then delete teh parttions and recreate it using a calculated size.

    Creating and re-creating a partion is very fast.  It is the format that is slow. YOU can see the partition size after it is created even if it is not formatted.

    I do not believe WMI can see an unformatted disk.  WMI looks through the OS drivers and reports only what the OS sees. WIndows cannot see an unformatted disk. Disk Manager can but it is the utility that creates the OS disk.

     

     

     


    jv
    Sunday, January 1, 2012 10:50 PM

All replies

  • Hello,

    I currently have a custom install disc that we use here at my job. It first opens in a WinPE environment. I have a .cmd script that then runs to begin partitioning the hard drive (does this using diskpart). I would like to modify this script to get the size of the hard drive (disk 0) before actually doing the partitioning. I need to do this because the hdd may be different sizes depending on the machine , therefore if it is a bigger size the partitions will be bigger.

     I tried running chkdsk on the %systemdrive% to get the total disk size but that actually gave me the size of the temp ram on which the winpe environment resides. Any help on how to do this would be appreciated

     

     


    In modern OSs we do not partition disks as it kills performance and does not take advantage of the native disk structure.

    Parttioning was a tool that allowed large disks to be used before theOS was able to manage them.

    I highly recommend that you do no partition. 

    The only other reaon for parttioning that seems to be usefule is for building a recovery drive which allows the mani partition to be reformatted.

     


    jv
    Tuesday, December 27, 2011 5:14 PM
  • The recovery drive is exactly why we partition.

    But partitioning is not the problem, I just want to figure out how to get the size of hard disk 0 via batch script in the winpe environment


    Note: There are 3 hard drives in the machine, this is why i say disk 0
    • Edited by althurm Tuesday, December 27, 2011 6:28 PM
    Tuesday, December 27, 2011 6:27 PM
  • The recovery drive is exactly why we partition.

    But partitioning is not the problem, I just want to figure out how to get the size of hard disk 0 via batch script in the winpe environment


    Note: There are 3 hard drives in the machine, this is why i say disk 0

    A recovery drive has a minimum size requirement.  It is usually about 5 or 10Gb. It is trivial in size compared to todays drives.  Just make the first partition 90% of the drive and the rest will be big enough for the recovery drive.

    You might be able to get teh size using WMI but you would have to add teh package to your WinPE image.

    I don't think there is any way to do this in a batch script.

     

     


    jv
    • Edited by jrv Tuesday, December 27, 2011 7:19 PM
    Tuesday, December 27, 2011 7:17 PM
  • The recovery drive is exactly why we partition.

    But partitioning is not the problem, I just want to figure out how to get the size of hard disk 0 via batch script in the winpe environment


    Note: There are 3 hard drives in the machine, this is why i say disk 0

    A recovery drive has a minimum size requirement.  It is usually about 5 or 10Gb. It is trivial in size compared to todays drives.  Just make the first partition 90% of the drive and the rest will be big enough for the recovery drive.

    You might be able to get teh size using WMI but you would have to add teh package to your WinPE image.

    I don't think there is any way to do this in a batch script.

     

     


    jv

    I was afraid of that. I did figure out how to do it with a vbscript. Like you said I had to add WSH package to the winpe image. Just wondering if there was a simple batch script solution before I went that route. thanks
    • Edited by althurm Tuesday, December 27, 2011 7:24 PM
    Tuesday, December 27, 2011 7:23 PM
  • Yes - WSH would also work and is probably the easiest approach.

    All-inall VBScript is much easier to work with in PE.  Batch scripts are only useful if yopu are a master at batch.  Few people today are orm like you, do not recognoze the limitations.

    There is a utility that will get disk size but like WSH it can only see the partitioned disks.

    With WSH you can  run diskpart list disk and get the size I believe.  Only certain low level programs can see an unpartitioned disk. 

    You might also search the WDT site for other utilities that can report raw disk size.

     

     


    jv
    Tuesday, December 27, 2011 7:43 PM
  • You may have the WMIC.EXE command in your PE environment already. If so, you can use it to query WMI.
    Wednesday, December 28, 2011 3:29 PM
  • You may have the WMIC.EXE command in your PE environment already. If so, you can use it to query WMI.


    Rob - YOu have to specifically select to add WMI support to get WMIC.

    Yes- WMIC is very easy to use in a batch script.  Unfortuanley I do not believe it is available for WinPE.

    I also discovered that you have to add WSH support specifically in order to use the WMI provider.

    Here is the list of WnPE packages through WS2008R2.

    THe OP could just create a simple scipt to return disk size but you would have to first partition the disk at full size.  You cannot read a raw disk with WMI.  Diskpart can read a raw disk but it is a bit difficult to get the size but it can be done.

    Diskpart cancreate a partition th efull size of teh drive and then listing the partitoin will give its size.  You can then delete teh parttions and recreate it using a calculated size.

    Creating and re-creating a partion is very fast.  It is the format that is slow. YOU can see the partition size after it is created even if it is not formatted.

    I do not believe WMI can see an unformatted disk.  WMI looks through the OS drivers and reports only what the OS sees. WIndows cannot see an unformatted disk. Disk Manager can but it is the utility that creates the OS disk.

     

     

     


    jv
    Sunday, January 1, 2012 10:50 PM