Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change drive letters of volume winXP

Status
Not open for further replies.

kumar3698

IS-IT--Management
May 19, 2013
7
IN
Want to change drive letter of volumes. once the script is run it should show the partitions in pop up box and ask for new drive letters.

Used below code but it is just changing the d to q

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

Set colVolumes = objWMIService.ExecQuery _
("Select * from Win32_Volume Where Name = 'D:\\'")

For Each objVolume in colVolumes
objVolume.DriveLetter = "Q:"
objVolume.Put_
Next
 
Used below code but it is just changing the d to q
take away the D: qualification

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume")

For Each objVolume in colVolumes
   strDrive = inputBox("Enter new drive letter (e.g. c:)")
   objVolume.DriveLetter = strDrive
   objVolume.Put_
Next

-Geates

 
Hello friend Its not working and giving the below error in XP

script D:\driveletter.vbs
line 5
char 1
error 0x80041010
code 80041010
source (null)
 
What is line 5 in your script? In what I posted, it's the [tt]for each[/tt] loop. An error here would suggest the colVolumes is empty - which further suggests either a corrupt WMI on the computer or that information thru WMI is protected by software or something.

I do not get an error.

Also, I added a line.

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume")

For Each objVolume in colVolumes
	[highlight #FCE94F]if (objVolume.DriveLetter <> "") then[/highlight]
		strDrive = inputBox("Curren Letter: " & [highlight #FCE94F]objVolume.DriveLetter[/highlight] & chr(10) & "Enter new drive letter (e.g. c:)")
		objVolume.DriveLetter = strDrive
		objVolume.Put_
	[highlight #FCE94F]end if[/highlight]
Next

-Geates

 
Hello friend -It works in Windows 7 but not in XP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top