Jump to content

WinPE2 Volume ID's


AndeeOPT

Recommended Posts

Hi All,

needed some help with a WinPE2 bootable Ramdisk DVD I am making.

I am using the disc to contain a ghost or imagex image which is dumped to the HDD.

Before the dumping, the HDD is cleaned, partitioned, formatted and made active.

I then want to assign drive letter Z: to the optical drive.

I just have a CMD file which runs diskpart is script mode which selects volume x and assigns Z to it.

This works fine if there is only a HDD and OPTICAL but if there is a card reader on the system there are more volumes and the optical volume id changes all the time.

I have worked around this by adding in user invention where the user specifies the volume id of the optical from list volumes which is given a variable.

But I would really like to have the whole process automated. Someone has told me this could be done using WMI.

So my question after all this is - how can a WMI script be made which selects the correct volume of the optical at any particular time?

Cheers

Link to comment
Share on other sites


You could use something like this to create a diskpart script to set the optical drive letter to Z, assuming you only have one optical drive connected.

strComputer = "."
Set objWMIService = GetObject(_
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery( _
"Select * from Win32_CDROMDrive")
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtfile = fso.CreateTextFile("setOpticalVolume.txt")

if colItems.Count = 1 then
for each objItem in colItems
txtfile.WriteLine "SELECT VOLUME " & objItem.ID
txtfile.WriteLine "ASSIGN Z"
txtfile.WriteLine "EXIT"
next
end if

txtfile.Close

Run the WIM script, which will create setOpticalVolume.txt. Run setOpticalVolume.txt as a diskpart script.

Edited by zorphnog
Link to comment
Share on other sites

Thanks zorph, but that appears to be the same as what I have done now except that instead of the WMI Script I have used a CMD file.

If I read your script correctly, it is still relying on the TXT file which would have 'select volume x' & 'assign drive=z'

I need something that will select the volume of the optical no matter what volume id it currently is.

Ideally I wish you could assign a drive letter by selecting the filesystem or device type.

Link to comment
Share on other sites

I'm not quite sure if I understand you correctly. The script I posted queries WMI for all optical drives attached to the system and returns a collection of the optical drives. In this case I am assuming that there is only one optical drive attached to the system (if colItems.Count = 1). The optical drive letter is written to the setOpticalVolume.txt file (txtfile.WriteLine "SELECT VOLUME " & objItem.ID) where objItem.ID is the drive letter of the optical drive. This setOpticalVolume.txt file is written during the execution of the script so it will always correspond to the current drive letter of the optical drive.

I would use it as a part of your cmd file. Note: .cmd file, cleanPartitionFormat.txt, and getOpticalVolume.vbs are all in the same directory.

@rem Script to clean partition and format HDD
diskpart /s cleanPartitionFormat.txt

@rem Run the WMI script i posted
cscript getOpticalVolume.vbs

@rem Assign Z to optical drive letter
diskpart /s setOpticalVolume.txt

If I understand your situation correclty this should work. Have you even tried it?

Edited by zorphnog
Link to comment
Share on other sites

zorph,

I apologise for my mistake. I am not good at scripting and I tried to make sense of your script without actually trying it.

I have tried now and it DOES work. There was a mistake in the setOpticalvolume.txt, that being the line "ASSIGN Z" which had to be changed to "ASSIGN LETTER=Z"

However, I now have a problem if I have a card reader installed with the selection of the HDD.

The issue is I am using imagex and tell it to dump a WIM file to C:\ but when a card reader is installed, one of it's drives has the letter C:\

imagex runs from a CMD file.

Only one HDD.

Any ideas would be great!

Link to comment
Share on other sites

I have the same problem with card readers as they already use the C: if the HDD is blank.

As a temporary solution I have used a Script that removes all the drive letters in Diskpart so I can ther assign the C: drive letter to the HDD.

Select volume 0
remove noerr
select volume 1
remove noerr
select volume 2
remove noerr
select volume 3
remove noerr
select volume 4
remove noerr
select disk 0
clean
select disk 0
create partition primary size=20000
active
assign letter c:
create partition primary size=%partsize%
assign letter d:
create partition primary
assign letter e:
Select Volume 0
Assign Letter f:
exit

Link to comment
Share on other sites

Hi Robbo,

I used what you said but changed it for my need as if I did exactly what you posted it would zorph's script to not work because:

If I use the script to assign letter z to optical and then have diskpart remove all the drive letters, then optical loses Z:

If I run the script after all drive letters have been removed, then the script won't work as it depends on the optical already having a drive letter.

So what I did was to the select volume which had been assigned drive letter C, remove it with no errors and then select my HDD, create partition, make active, assign drive letter c (which is now not being used) and format the partition.

Zorph's script is the first thing run, so this will work and if the optical happens to have letter C initially, the script runs by selecting C and then changing it Z which then leaves C free to be assigned to the HDD.

So I have a CMD which runs diskpart in script mode using the following TXT file:

Select volume C
remove noerr

select disk 0
clean
create partition primary
active
assign letter=c
select partition 1
format fs=ntfs label="[whatever you want]" quick

Edited by AndeeOPT
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...