Set/Change CD-ROM drive letter with VBS 
Author Message
 Set/Change CD-ROM drive letter with VBS

Hi,
is it possible to change the CD-ROM drive letter with VBS? During our
automated installation will want to change the drive letter of the CD-ROM to
"z:"...

Thanks for help in advance



Tue, 13 Jul 2004 22:16:23 GMT  
 Set/Change CD-ROM drive letter with VBS

Quote:

> Hi,
> is it possible to change the CD-ROM drive letter with VBS? During our
> automated installation will want to change the drive letter of the CD-ROM to
> "z:"...

Hi

From an another thread:

<qoute>

Subject: Re: Change Driveletter to Z:\
Newsgroups: microsoft.public.scripting.wsh
Date: 2002-01-21 19:30:38 PST

Get cdrom drive letter using WMI
I had hard time to use regwrite to overwrite value of
"HKEY_LOCAL_MACHINE\System\MountedDevices"
so I have dumpet tihs key to a reg file,
deleted the key "HKEY_LOCAL_MACHINE\System\MountedDevices"
looked for and changed the drive letter in the file,
dump this file back.
alexseys

Quote:


>hello NG

>I am looking for a way to change the letter of my CD-Rom to Z:\ by using a
>script. Can anybody tell me how I can do this.

>I'm thankful for all of your help

>Greetings Chris

</qoute>

--
torgeir



Wed, 14 Jul 2004 01:50:26 GMT  
 Set/Change CD-ROM drive letter with VBS
Fleshing out what Torgeir says-

If there is ONLY one CD-ROM  drive present (or you only want the first
instance to be changed) you can use the canned code from the help docs
to track it down:

wscript.echo ShowDriveType("D")

Function ShowDriveType(drvpath)
   Dim fso, d, t
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set d = fso.GetDrive(drvpath)
   Select Case d.DriveType
      Case 0: t = "Unknown"
      Case 1: t = "Removable"
      Case 2: t = "Fixed"
      Case 3: t = "Network"
      Case 4: t = "CD-ROM"
      Case 5: t = "RAM Disk"
   End Select
   ShowDriveType = "Drive " & d.DriveLetter & ": - " & t
End Function

for that drive, you should see something like the following as a
registry key name:

\DosDevices\D:

with a binary value.   At that point unless you want to go through WMI
(which is a better way to change it even if more complex) you pretty
much have to dump the registry value, delete it, then mod the path and
reimport...

When you have a drvpath that returns "CD-ROM", you have

Quote:

> > Hi,
> > is it possible to change the CD-ROM drive letter with VBS? During
our
> > automated installation will want to change the drive letter of the
CD-ROM to
> > "z:"...

> Hi

> From an another thread:

> <qoute>

> Subject: Re: Change Driveletter to Z:\
> Newsgroups: microsoft.public.scripting.wsh
> Date: 2002-01-21 19:30:38 PST

> Get cdrom drive letter using WMI
> I had hard time to use regwrite to overwrite value of
> "HKEY_LOCAL_MACHINE\System\MountedDevices"
> so I have dumpet tihs key to a reg file,
> deleted the key "HKEY_LOCAL_MACHINE\System\MountedDevices"
> looked for and changed the drive letter in the file,
> dump this file back.
> alexseys



> >hello NG

> >I am looking for a way to change the letter of my CD-Rom to Z:\ by
using a
> >script. Can anybody tell me how I can do this.

> >I'm thankful for all of your help

> >Greetings Chris

> </qoute>

> --
> torgeir



Wed, 14 Jul 2004 02:43:50 GMT  
 Set/Change CD-ROM drive letter with VBS
Rolf,

This is a section from my RIS script

Regards
John Facci

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Change CD Rom Drive Letter to R:
' Requires reboot before it takes effect.
' Auto registers "RegObj.Dll" 'This will have been copied to System32 dir
during RIS install.
' Enumerates all mounted devices
'  saves key name of last CD found
'  ensures R: not already used
' Created new key for CD with letter of R:
' Deleted old Key.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub CDROM
   On Error Resume Next
   Dim objRegistry, objRootKey, objRegKey
   Dim objDevice
   Dim strDevice, strDriveLetter, d
   Dim strFound    ' Store Name of device to rename
   Dim strTemp, strNewKey
   Dim strReg
   Dim f, result

   Set objRegistry = WScript.CreateObject("RegObj.Registry")
   If err.number <> 0 then 'DLL must not be registered
   RegDLL "Regobj.dll" 'Attempt Automatic Registration.
  Err.Clear
  '  Try creating object again
 Set objRegistry = WScript.CreateObject("RegObj.Registry")
 if err.number <> 0 then 'DLL STILL not registered.
    ErrHandler "Error: Auto registration of DLL failed"
 End IF
   End if

   strFound = ""
   Set objRootKey =
objRegistry.RegKeyFromString("\HKEY_LOCAL_MACHINE\System\MountedDevices")
   ' Loop through all Devices
   For Each objDevice In objRootKey.Values
         strDevice = objDevice.Name
         ' Is this a Device we are interested in
         If Len(strDevice)=14 Then
            If Left(strDevice,12) = "\DosDevices\" Then
               ' Extract Drive Letter
               strDriveLetter = Right(strDevice,2)
               If strDriveLetter = "R:" Then 'Letter already in use
                  LogMsg "Unable to rename CDROM as R: already in use"
                  Exit Sub
               End if
               If  strDriveLetter = "A:" or strDriveLetter = "B:" or
strDriveLetter = "C:" Then
                  ' Do nothing as we are not interested in A:, B: or C:
               Else
                  ' Check to see if the drive is a CDROM
                  Set d = fso.GetDrive(strDriveLetter)
                  If d.DriveType = 4 Then
                     strFound = strDevice   'Save Device name for later
usage.
                  End if
               End if
            End if
         End if
   Next 'objDevice
   Set objRootKey = Nothing
   If strFound = "" Then
      LogMsg "No CDROM found on this PC"
      Exit Sub
   End if
   ' We get here if we found a CDROM device to rename
   ' Read its Value (Binary) as we need value to create a new Key based on
R:
   ' We must use RegObj to read the Key as the Value contains a "\" which is
not supported by RegRead
   strTemp =""

   ' The registry key we are creating in a Binary Array, VBScript only
supports an array variant
   ' this is not good enough for RegObj.DLL
   ' In order to create the new key we must create a temporary .REG file and
import it.

   ' Read current Value, this is a VarType of 8209 - Binary Array
   strTemp =  RegRead("\HKEY_LOCAL_MACHINE\System\MountedDevices" ,
strFound)
   BugCheck "Error: CDROM() - Error Reading Value: " & strFound

   ' Convert Byte Array to Hex Character String
   strTemp = ByteArray(strTemp)

   ' We must create a string to write to the Temp.REG file
   strReg = "Windows Registry Editor Version 5.00" & vbCRLF & vbCRLF
   strReg = strReg & "[HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices]" & vbCRLF &
vbCRLF
   strReg = strReg & Chr(34) & "\"
   ' Add Key name to Value
   strTemp = "\DosDevices\\R:" & chr(34) & "=hex:" & strTemp
   ' Split The Binary data into Lines 75 chars long (looks better in the
.Reg file
   Do While Len(strTemp) > 75
      strReg = strReg & Left(strTemp,75) & "\" & vbcRLF & "  "
      strTemp = Right(strTemp,Len(strTemp)-75)
   Loop
   ' Add remaining Array characters (there may have been less that 75 on the
last line
   strReg = strReg & strTemp & vbCRLF

   ' Create .REG File in Temp directory
   Set f = fso.OpenTextFile(WshSysEnv("TEMP") & "\RIS.REG", ForWriting,
True)
   f.WriteLine strReg
   f.close
   BugCheck "Error: CDROM() - Error creating .REG file.'"

   ' Import Registry settings
   result = WshShell.Run ("Regedit.exe /S " & WshSysEnv("TEMP") &
"\RIS.REG", 1, True)

   ' Ensure new registry entry is present, before deleting the old one.
   strTemp =  RegRead("\HKEY_LOCAL_MACHINE\System\MountedDevices", strFound)
   BugCheck "Error: CDROM() - Error Reading Value: " & strFound
   ' Read New Value
   strReg = RegRead("\HKEY_LOCAL_MACHINE\System\MountedDevices",
Left(strFound,Len(strFound)-2) & "R:")
   BugCheck "Error: CDROM() - Error Reading Value: " &
Left(strFound,Len(strFound)-2) & "R:"
   If Ubound(strReg) <> UBound(strTemp) Then
      ErrHandler "CDROM() - New Registry value dosn't match old one"
      ' This is a issue as we now have a cactus registry entry for R:
   End if

   ' Delete old Key
   'WshShell.RegDelete("HKEY_LOCAL_MACHINE\System\MountedDevices\" &
strFound)

   ' Get the key containing the value we want to remove
   Set objRootKey =
objRegistry.RegKeyFromString("\HKEY_LOCAL_MACHINE\System\MountedDevices\")
   ' Remove the Value from the Values collection
   objRootKey.Values.Remove (strFound)
   BugCheck "Error: CDROM() - Error deleting existing key"

   ' Delete temp .REG file
   fso.DeleteFile(WshSysEnv("TEMP") & "\RIS.REG")
   BugCheck "Error: CDROM() - Error deleting temp .REG file: " &
WshSysEnv("TEMP") & "\RIS.REG"

   LogMsg "Assigned R: to CDROM, reboot for this to take effect"
   On Error Goto 0
End Sub


Quote:
> Hi,
> is it possible to change the CD-ROM drive letter with VBS? During our
> automated installation will want to change the drive letter of the CD-ROM
to
> "z:"...

> Thanks for help in advance



Sat, 17 Jul 2004 07:56:17 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Change CD-ROM Drive Letter

2. Change CD-ROM Drive Letter

3. Retrieving drive letter for user's cd-rom drive

4. Newby: Determine CD-ROM drive letter

5. CD-Rom Drive Letter

6. Finding CD-ROM Drive Letter

7. CD-ROM drive letter?

8. CD-ROM drive letter. VB5

9. CD Rom Drive Letter

10. cd-rom drive letter prob

11. Use VB4 to determine CD-ROM drive letter?

12. Help: CD-ROM drive letter?

 

 
Powered by phpBB® Forum Software