mbkowns Posted September 17, 2008 Share Posted September 17, 2008 I would like to make an AutoIT script that renames drive letters if they are in use. We got many new systems that came with USB card readers that took some of the network drive letters we use. Another problem we have is USB sticks / hard drives that end up using out network letters. I would say its maybe 1% of users getting this problem which isn't very many but I would like to make sure this doesn't happen anyway.Persistant Mappings aren't a problem becuase you can delete them.net use q: /dSo after I detect a drive letter in use withDriveGetDrive I need to be able to rename the drive letter to a defined list of drive letters.Renaming CDROMS, Local Hard drives, USB sticks, USB card readers.I have looked at diskpart but I am not sure how I could use this in my situtation. I could parse the diskpart log and make changes from that but I think that is kinda sloppy anyother ideas?Thanks Link to comment Share on other sites More sharing options...
Andreik Posted September 17, 2008 Share Posted September 17, 2008 You can set the drive letter from registry key. You can find the registry here: HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices Use Reg functions to modify the letter of drive. Maybe exists other best way. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
mbkowns Posted September 17, 2008 Author Share Posted September 17, 2008 You can set the drive letter from registry key.You can find the registry here: HKEY_LOCAL_MACHINE\SYSTEM\MountedDevicesUse Reg functions to modify the letter of drive.Maybe exists other best way. I forgot to mention that I know about that and its easy also but it won't change the letters until next reboot. Link to comment Share on other sites More sharing options...
Joon Posted September 17, 2008 Share Posted September 17, 2008 You can convert this vbs to AutoIt 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 Link to comment Share on other sites More sharing options...
DaRam Posted September 17, 2008 Share Posted September 17, 2008 Something missing here?objVolume.Put_<what?>Next Link to comment Share on other sites More sharing options...
Joon Posted September 17, 2008 Share Posted September 17, 2008 Nope, that's the command... Convert to AutoIt anyway. $objWMIService = ObjGet("winmgmts:\\.\root\cimv2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Volume WHERE Name= 'Q:\\'") For $colItem In $colItems $colItem.DriveLetter = "S:" $colItem.Put_ Next Something missing here? Link to comment Share on other sites More sharing options...
DaRam Posted September 17, 2008 Share Posted September 17, 2008 My bad, I did not look closely enuf' to not confuse the _ in $colItem.Put_ with a line continuation. Nope, that's the command... Convert to AutoIt anyway. $objWMIService = ObjGet("winmgmts:\\.\root\cimv2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Volume WHERE Name= 'Q:\\'") For $colItem In $colItems $colItem.DriveLetter = "S:" $colItem.Put_ Next Link to comment Share on other sites More sharing options...
cherdeg Posted September 24, 2008 Share Posted September 24, 2008 BTW: The WMI class "Win32_Volume" is NOT available on Windows 2000 and Windows XP. Does anybody know a way to change a drive letter there without having to reboot? The "Disk Management" mmc can do it, so why can't we? Link to comment Share on other sites More sharing options...
mbkowns Posted September 24, 2008 Author Share Posted September 24, 2008 BTW: The WMI class "Win32_Volume" is NOT available on Windows 2000 and Windows XP. Does anybody know a way to change a drive letter there without having to reboot? The "Disk Management" mmc can do it, so why can't we?The code above your post worked for me renaming a driver letter so maybe you didn't fully test it change Q to the drive want to change and S to the drive you want it to change to.I need to play with it more to see if it will work for my purpose though. Link to comment Share on other sites More sharing options...
ResNullius Posted September 24, 2008 Share Posted September 24, 2008 (snip)I have looked at diskpart but I am not sure how I could use this in my situtation. I could parse the diskpart log and make changes from that but I think that is kinda sloppy anyother ideas?ThanksCheck out this thread,http://www.autoitscript.com/forum/index.php?showtopic=62519 Link to comment Share on other sites More sharing options...
mbkowns Posted September 25, 2008 Author Share Posted September 25, 2008 Check out this thread,http://www.autoitscript.com/forum/index.php?showtopic=62519I have but it doesn't work with all the drive types I want to rename. Link to comment Share on other sites More sharing options...
ResNullius Posted September 25, 2008 Share Posted September 25, 2008 I have but it doesn't work with all the drive types I want to rename.Are you very familiar with diskpart?I have no trouble using it to re-assign drive letters for CDROMS, Local Hard drives, USB sticksThe only one I haven't tried is a USB card reader that but shouldn't be any different.Using it with a diskpart script file works great.More diskpart info at http://support.microsoft.com/kb/300415 Link to comment Share on other sites More sharing options...
mbkowns Posted September 25, 2008 Author Share Posted September 25, 2008 Are you very familiar with diskpart?I have no trouble using it to re-assign drive letters for The only one I haven't tried is a USB card reader that but shouldn't be any different.Using it with a diskpart script file works great.More diskpart info at http://support.microsoft.com/kb/300415Does it rename and let you use the renamed letter without rebooting? show me your script Link to comment Share on other sites More sharing options...
ResNullius Posted September 25, 2008 Share Posted September 25, 2008 (edited) Does it rename and let you use the renamed letter without rebooting? show me your scriptYes! Did you even try anything??? For easiest automation, first you create a diskpart script (not an AutoIt script) that contains the diskpart commands to execute. Then, use AutoIt to run diskpart with its script file. Here is the diskpart script file to change a drive wiith the letter "E" to letter "G" SELECT VOLUME E ASSIGN LETTER G Save that with a name like "E2G.txt". Note: the extension doesn't matter. Then use AutoIt to run diskpart and execute the saved script (note: for English OS only, tested on XP) #include <Constants.au3> $pid = Run(@SystemDir & '\diskpart.exe /s "' & @ScriptDir & '\E2G.txt"', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $dpResult = StdoutRead($pid) If @error Then ExitLoop Select Case StringInStr(StringUpper($dpResult), "NO VOLUME SPECIFIED") Or StringInStr(StringUpper($dpResult), "THE ARGUMENTS YOU SPECIFIED FOR") MsgBox(4096 + 16, "Error", $dpResult) ExitLoop Case StringInStr(StringUpper($dpResult), "DISKPART SUCCESSFULLY ASSIGNED") MsgBox(4096, "Success", $dpResult) EndSelect WEnd While 1 $line = StderrRead($pid) If @error Then ExitLoop MsgBox(0, "STDERR read:", $line) WEnd Of course, you can get creative and have your AutoIt script dynamically create the diskpart script file on the fly based on your use of DriveGetDrive() and DriveGetType() etc. And you can create your own custom success/error messages. If you look at Greenhorn's post http://www.autoitscript.com/forum/index.ph...st&p=468408 in that thread I pointed to earlier, you will see a method of parsing the output to check the results of diskpart commands issued to list the drives, etc. Edit: Fixed a incorrect variable in the StderrRead(); damn cut-n-paste... Edited September 25, 2008 by ResNullius Link to comment Share on other sites More sharing options...
cherdeg Posted October 30, 2008 Share Posted October 30, 2008 (edited) The code above your post worked for me renaming a driver letter so maybe you didn't fully test it change Q to the drive want to change and S to the drive you want it to change to.Then probably you use Vista. As I said: the class is not existent on pre-Vista OSses, so it definitely won't work. Just google "XP Win32_Volume" and you will see my statement confirmed within the first three results. Maybe you tried one of the other solutions before and that already had worked, but you didn't notice. Using WMI and Win32_Volume DOES NOT WORK on XP.Just use my solution:http://www.autoitscript.com/forum/index.ph...04&hl=drive Edited October 30, 2008 by cherdeg Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now