Jump to content

Recommended Posts

Posted

Thanks,

But how would I use this program to rename the drive letter of the cd rom to R:, how would I use this to tell me what letter the cdrom is and to remove that letter and assign R:?

Thanks in advance!


Posted

test.exe doesn't do anything with drive letter ! It detects just what type of drives and if the condition is right it launch a program.

Posted (edited)

Here is a VBS script that search for CD and checks if It a RW then it alllow you to change the drive letter.

strComputer = "."

On Error Resume Next

Dim Act, CD,ChangeDrv,Fso,MyPos,SearchString,SearchChar,SD

Set Act = CreateObject("Wscript.Shell")

Set Fso = CreateObject("Scripting.FileSystemObject")

SD = Act.ExpandEnvironmentStrings("%Systemdrive%")

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

Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")

'''' GET THE CDROM DRIVE LETTER

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function CD_Get_Drive

For Each objItem in colItems

SearchString = objItem.Caption

MyPos = Instr(1, SearchString, "RW")

CD = objItem.Drive

If MyPos = 1 Then

MsgBox "This Is Not A CD-RW", 0 + 32, "Not A CD-RW"

Exit Function

Else

SearchChar = "Caption: " & objItem.Caption & vbCrLf & "Name: " & objItem.Name & vbCrLf & CD

Act.Popup SearchChar, 5, "Confirm CD-RW",0 + 32

Change_CD_Letter

'''''PLACE THE SOFTWARE INSTALL PART BELOW HERE

''Act.Run(ChangeDrv & "\THE_FOLDER\THE_APP SWITCHES_FOR_INSTALL),1,True

'''''END THE SOFTWARE INSTALL HERE

Exit For

End If

Next

End Function

'''' CHANGE DRIVE LETTER HERE

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function Change_CD_Letter

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

Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume Where Name = '" & CD & "\\'")

For Each objVolume in colVolumes

ChangeDrv = InputBox("Please type in the new drive letter you would like to assign to the drive" &_

vbCrLf & "The current Drive Letter Is : " & CD & vbcrlf & "Example Z: or Y:","Change Drive" )

objVolume.DriveLetter = "" & ChangeDrv & ""

objVolume.Put_

Next

Exit Function

End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

CD_Get_Drive

Act.Popup "Completed CD Drive Letter Change" &_

vbCrLf & "Old CD Drive Letter : " & CD &_

vbCrLf & "New CD Drive Letter : " & ChangeDrv, 7,"Finished", 0 + 32

If Fso.FileExists(SD & "\CD_ChangeLetter.vbs") Then

Fso.DeleteFile(SD & "\CD_ChangeLetter.vbs")

End If

Edited by gunsmokingman
Posted

I like the script but when I run it,

I get a confirm on the:

"Act.Popup SearchChar, 5, "Confirm CD-RW",0 + 32", it goes away or I can click "Ok".

Then I get the:

"Act.Popup "Completed CD Drive Letter Change" &_

vbCrLf & "Old CD Drive Letter : " & CD &_

vbCrLf & "New CD Drive Letter : " & ChangeDrv, 7,"Finished", 0 + 32"

It seems to skip the whole Function Change_CD_Letter The new drive letter text is "" (blank) and it doesn't change anything on the drive. Any ideas?

Posted (edited)

Thanks for your help, I got it figured out. I use 3 .vbs scripts 2 .bat files and 2 diskpart.exe script text files to remove the drive letter from the cd-rom and assign it the letter r:, find out what disk (0) or (1) the 4G volume c: is on and create another partition with the letter e: out the remaining space and format it.

I am sure there is a prettier and easier way but this is the first time I have used scripts. I got all the code straight from the Microsoft script site and cut and paste as required.

What I am doing:

I call the scripts in this order from GuiRunOnce

***********Script 1: attrib.vbs************************************************************

'modifies the attributes of two diskpart script files called "disk0.txt" and "disk1.txt" to make sure they

' are not readonly.

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.GetFile("C:\install\disk0.txt")

If objFile.Attributes AND 1 Then

objFile.Attributes = objFile.Attributes AND 0

' Wscript.Echo "Read-only."

End If

Set objFile = objFSO.GetFile("C:\install\disk1.txt")

If objFile.Attributes AND 1 Then

objFile.Attributes = objFile.Attributes AND 0

' Wscript.Echo "Read-only."

End If

**********Script 2: drive.vbs*************************************************************

'1. Finds Volume Letter of CD-Rom

'2. Modifies a "diskpart.exe" script file called disk0.txt and another disk1.txt to include the command

' "select volume" and the returned drive letter in line 1. (example: "select volume D:")

Const FOR_READING = 1

Const FOR_WRITING = 2

strFileName0 = "C:\install\disk0.txt"

strFileName1 = "C:\install\disk1.txt"

strNewContent = "select volume "

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

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

& strComputer & "\root\cimv2")

Set colDisks = objWMIService.ExecQuery _

("Select * from Win32_LogicalDisk")

For Each objDisk in colDisks

' Wscript.Echo "DeviceID: "& vbTab _

' & objDisk.DeviceID

Select Case objDisk.DriveType

Case 1

Case 2

Case 3

Case 4

Case 5

'Write it to the First File "disk0.txt"

Set objFS = CreateObject("Scripting.FileSystemObject")

Set objTS = objFS.OpenTextFile(strFileName0,FOR_READING)

strContents = objTS.ReadAll

objTS.Close

Set objTS = objFS.OpenTextFile(strFileName0,FOR_WRITING)

'this next line write the string into the first line of the text file

objTS.WriteLine strNewContent & objDisk.DeviceID

objTS.Write strContents

'Write to the Second File "disk1.txt"

Set objFS = CreateObject("Scripting.FileSystemObject")

Set objTS = objFS.OpenTextFile(strFileName1,FOR_READING)

strContents = objTS.ReadAll

objTS.Close

Set objTS = objFS.OpenTextFile(strFileName1,FOR_WRITING)

'this next line write the string into the first line of the text file

objTS.WriteLine strNewContent & objDisk.DeviceID

objTS.Write strContents

Case 6

Case Else

End Select

Next

**********Script 3: drivetopart.vbs*********************************************************

'Finds the disk id (Disk 0 or Disk 1) of C: drive and launches the correct correct bat file so I can create

'E: drive out of the remaining space.

'Tells us which letter goes with what partition..

ComputerName = "."

Set wmiServices = GetObject ( _

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

& ComputerName)

' Get physical disk drive

Set wmiDiskDrives = wmiServices.ExecQuery ( _

"SELECT Caption, DeviceID FROM Win32_DiskDrive")

For Each wmiDiskDrive In wmiDiskDrives

'Use the disk drive device id to

' find associated partition

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

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

Set wmiDiskPartitions = wmiServices.ExecQuery(query)

For Each wmiDiskPartition In wmiDiskPartitions

'Use partition device id to find logical disk

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

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

objShell.Run("%comspec% /K c:\install\edrive0.bat"), 1, True

end if

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

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

objShell.Run("%comspec% /K c:\install\edrive1.bat"), 1, True

end if

Next

Next

Next

##################The other files#########################

********* edrive0.bat

%windir%\system32\diskpart.exe /S c:\install\disk0.txt > c:\install\drivelog.txt

echo Y | %windir%\system32\format e: /fs:ntfs /q /v:""

*********edrive1.bat*****************

%windir%\system32\diskpart.exe /S c:\install\disk1.txt > c:\install\drivelog.txt

echo Y | %windir%\system32\format e: /fs:ntfs /q /v:""

*********drive0.txt 'this is a diskpart script file*********************

'select volume e: This is what drive.vbs will write ERASE THIS LINE IF YOU ARE USING THIS!!!

remove noerr

assign letter r

Select Disk 0

Create partition primary

assign letter e

exit

*********drive1.txt 'this is a diskpart script file*********************

'select volume e: This is what drive.vbs will write ERASE THIS LINE IF YOU ARE USING THIS!!!

remove noerr

assign letter r

Select Disk 1

Create partition primary

assign letter e

exit

I hope this helps someone, I know it is dirty code and I am not sure how to post it in the pretty quote box.

Like I said I cut and paste from the Microsoft site. I know it works for my app!

Thanks again

Edited by Tracy7011
Posted

Here is the 3VBS scripts as one VBS script try this and see if it works still

Const FOR_READING = 1, FOR_WRITING = 2

ComputerName = "."

strComputer = "."

Dim MyFile '''' REPLACES THESE VARIBLES NAMES ,strFileName0,strFileName1,strNewContent

MyFile = Array("C:\install\disk0.txt","C:\install\disk1.txt","select volume")

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.GetFile(MyFile(0))

If objFile.Attributes AND 1 Then

objFile.Attributes = objFile.Attributes AND 0

End If

Set objFile = objFSO.GetFile(MyFile(1)) ''''USINF THE ARRAY VARIBLE HERE NOW

If objFile.Attributes AND 1 Then

objFile.Attributes = objFile.Attributes AND 0

End If

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

Set objFS = CreateObject("Scripting.FileSystemObject")

Set objTS = objFS.OpenTextFile(MyFile(0),FOR_READING)

strContents = objTS.ReadAll

objTS.Close

Set objTS = objFS.OpenTextFile(MyFile(0),FOR_WRITING)

objTS.WriteLine MyFile(2) & objDisk.DeviceID

objTS.Write strContents

objTS.Close

Set objTS = objFS.OpenTextFile(MyFile(1),FOR_READING)

strContents = objTS.ReadAll

objTS.Close

Set objTS = objFS.OpenTextFile(MyFile(1),FOR_WRITING)

objTS.WriteLine MyFile(2) & objDisk.DeviceID

objTS.Write strContents

objTS.Close

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

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

objShell.Run("%comspec% /K c:\install\edrive0.bat"), 1, True

End If

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

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

objShell.Run("%comspec% /K c:\install\edrive1.bat"), 1, True

End If

Next

Next

Next

Posted (edited)

Thanks!

That works except there is a space after the word volume in "select volume" --> "select volume "

Change

MyFile = Array("C:\install\disk0.txt","C:\install\disk1.txt","select volume")

To

MyFile = Array("C:\install\disk0.txt","C:\install\disk1.txt","select volume ")

After I added the space it worked great.

Thanks alot, I will have to figure out the variable array....

Edited by Tracy7011
Posted

I took out that space I did not know if it was needed.

Just add it to the array with the space at the end.

This has the space added to the end.

MyFile = Array("C:\install\disk0.txt","C:\install\disk1.txt","select volume ")

Posted (edited)

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 od Code

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

Edited by Tracy7011

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...