Jump to content

Change CD Drive Letter w/Diskpart /w Unattended


Recommended Posts

'Just incase anyone needs an alternatvie to mapdrive.com found in this forum.

'mapdrive didn't work for me due to me wanting to make my second partition during install and I

'didn't know any of the disk numbers, volume numbers.

'I used this last night on several machines and it worked good. Interesting, All the machines I have

'checked that have one cd, windows always calls them volume 0

'From Topic:

'Determine if CD-R drive exists

'http://www.msfn.org/board/index.php?showtopic=60721&st=20

'Ok, I am done with this now.

'This script will:

'1. find your cd-rom drive letter.

'2. find the disk id of your hard disk

'3. create a diskpart txt script file to a. remove the cd-rom drive letter, b. assign cd a letter (r: in my case)

'c. create another partition on hard disk with remaining space and assign it letter e:

'4. Creates a batch file that a. launches diskpart with the above script file b. formats the newly

'created partition. We have to do it from a batch due to diskpart runs in its own little command line and

'want to know when it is complete so we can launch format as soon as it has created the partition.

'I had to do this due to the systems we use at work need a e: partition and the cd at r:, we have a zip

'so windows always put the cd at defualt of e: and you can never know if windows will call the hard disk

' disk 1 or disk 0.

'I call this script from GuiRunOnce in Unattended with no support files.

'************************DoDrives.vbs*********************

Const FOR_READING = 1, FOR_WRITING = 2

ComputerName = "."

strComputer = "."

Dim TF

DIM NewFile

DIM DefaultString

DIM CDDeviceID

DIM DiskNum

DefaultString = Array ("select volume ", "remove noerr", "assign letter r", "select disk ", _

"Create partition primary", "assign letter e", "exit")

NewFile = "C:\install\Disk.txt" 'We have to create a .txt script file for diskpart

NewBat = "C:\install\edrive.bat" 'We have to use a bat so we can launch format after we are done with diskpart

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" _

& strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _

("Select * from Win32_LogicalDisk")

For Each objDisk in colDisks

Select Case objDisk.DriveType

Case 1

Case 2

Case 3

Case 4

Case 5

CDDeviceID = objDisk.DeviceID

Case 6

Case Else

End Select

Next

Set wmiServices = GetObject ( _

"winmgmts:{impersonationLevel=Impersonate}!//" _

& ComputerName)

Set wmiDiskDrives = wmiServices.ExecQuery ( _

"SELECT Caption, DeviceID FROM Win32_DiskDrive")

For Each wmiDiskDrive In wmiDiskDrives

query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" _

& wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"

Set wmiDiskPartitions = wmiServices.ExecQuery(query)

For Each wmiDiskPartition In wmiDiskPartitions

Set wmiLogicalDisks = wmiServices.ExecQuery _

("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" _

& wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")

For Each wmiLogicalDisk In wmiLogicalDisks

If wmiDiskDrive.DeviceID = "\\.\PHYSICALDRIVE0" then

DiskNum="0"

End If

If wmiDiskDrive.DeviceID = "\\.\PHYSICALDRIVE1" then

DiskNum="1"

End If

Set TF=objfso.CreateTextFile(NewFile, True) 'Create a new script text file

TF.WriteLine (DefaultString(0)) & CDDeviceID 'select volume x: (x = CD Drive Letter)

TF.WriteLine (DefaultString(1)) 'remove noerr

TF.WriteLine (DefaultString(2)) 'assign letter r

TF.WriteLine (DefaultString(3)) & DiskNum 'select disk x (0,1)

TF.WriteLine (DefaultString(4)) 'Create partition primary

TF.WriteLine (DefaultString(5)) 'assign letter e

TF.WriteLine (DefaultString(6)) 'exit

TF.close 'Close the new file

Set TF=objfso.CreateTextFile(NewBat, True) 'Create a new batch file

TF.WriteLine "%windir%\system32\diskpart.exe /S c:\install\disk.txt > c:\install\drivelog.txt" 'This line launches diskpart

TF.WriteLine "echo Y | %windir%\system32\format e: /fs:ntfs /q /v:""" 'This line formats

TF.close 'Close the new file

Set objShell = WScript.CreateObject("WScript.Shell")

objShell.Run("%comspec% /K c:\install\edrive.bat"), 1, true 'Run the bat file

Next

Next

Next

'''''End Code

'''''Thanks gunsmokingman for putting the three scripts into one which led me making just one file to do it all.

Link to comment
Share on other sites


So what was mapdrive doing wrong...???

I am just curious, as I am a user of mapdrive, and given my system config, with 2 dvds, and 6 partitions... it works flawlessly for me.

mdes, the developer was also very helpful in assisting with a few mods to make it work better for my config, however, the latest release works fine.

Link to comment
Share on other sites

It kept telling me the cd rom was not reassignable. I am doing this on W2K, not sure if that is diff or not.

I also didn't have the second partition built yet, I have an automated format cd that makes c: 4G and formats it.

As I understood it, you need to add a file "drive.x" to each drive.

e: is assinged to the cd after install, I need it R before I create my second partition e.

Before I can make my partition I need to know what params to send to diskpart, (disk id). I then need to format it.

I am sure mapdrive can do it and the problems I was having was mistakes on my part. But here is another way to do what I needed.

Thanks for looking!

Edited by Tracy7011
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...