Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Easy way to assign drive letters


  • Please log in to reply
5 replies to this topic

#1 keyboardNinja

keyboardNinja

    Bleepin' Ninja


  • Members
  • 4,815 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:teh interwebz
  • Local time:11:50 AM

Posted 04 January 2010 - 02:06 PM

Here's my situation:

I have two virtual machines in my Microsoft Virtual PC. Vista and XP. The problem with them is this: the large vhd (virtual hard drive) files are always fragmenting and making it hard to keep my hard drive defragmented (I use Piriform's Defraggler). So, I fixed this problem by creating a partition for each virtual machine's vhd. I then mounted each partition in an empty ntfs folder through "Disk Management". This works great because Virtual PC doesn't know the difference, and the big vhd files can't fragment with my other files (making it harder to defragment). They each have their own little partition.

Now, I still want to be able to defragment these vhd's so my vm's don't get too slow. However, I don't want to leave them with drive letters because they show up in "My Computer". I tried "Defrag File" in Defraggler and pointing it to the vhd's (that are mounted in the ntfs folder), but it doesn't work. I guess Defraggler can't work in a partition mounted in a folder like that.

I was hoping I could make a batch file to do the commands necessary to assign drive letters. Then I could set Defraggler to schedule a defrag on these drives (then remove the driver letters afterwards). I can do it manually through the Disk Management, and also using the command prompt. But I wanted to be able to do by just double-clicking a file (a batch file, in my case).

Here is what I put in the batch file:

diskpart

select disk 0
select partition 4
assign letter=x
exit
exit

If I just double-click the batch file, then I get a command prompt, then a UAC prompt asking if I want to allow Diskpart to run (it requires administrator priveleges). After saying Yes, then I end up with the original command prompt that won't allow me to do anything (it is stuck with diskpart in it, and won't allow anything else to be done), and another one with diskpart already loaded. However, the commands from my batch file to select and assign the letter don't run. If I right-click the batch file and chose "Run as Administrator", I get the UAC prompt, diskpart loads in a single command prompt, but the select and assign commands still don't run.

If I copy the commands from the batch file to the clipboard (without the diskpart), then run the batch file, I get the two command prompts like usual. But if I right-click once inside the diskpart command prompt, the commands get pasted and run (only right-clicking once, nothing else). Then I get a window showing me my new disk (X: drive). Weird... But I can't get the commands to run by themselves. They will only run when I right-click inside the empty space in the diskpart window (if I've copied the commands to the clipboard).

Any idea as to why this happens and how to make the commands run after opening diskpart?

Or is there a third-party application that makes this easier?

When I get back to fast internet, I'll upload some screenshots and a screen-captured video of the problem.

Any advice until then would be great. :thumbsup:
PICNIC - Problem In Chair, Not In Computer

Posted Image Posted Image

20 Things I Learned About Browsers and the Web

BC AdBot (Login to Remove)

 


#2 tjn1987

tjn1987

  • Members
  • 2 posts
  • OFFLINE
  •  
  • Local time:12:50 PM

Posted 17 April 2010 - 12:01 PM

You would have to create two files: .bat and .txt

1) .txt file:

select disk 0
select partition 4
assign letter=x
exit
exit

save this .txt file as anyname.txt

2) .bat file:

diskpart /s anyname.txt


In case you want to see the result, the .bat file would be:

diskpart /s anyname.txt > result.txt

Edited by tjn1987, 17 April 2010 - 12:03 PM.


#3 keyboardNinja

keyboardNinja

    Bleepin' Ninja

  • Topic Starter

  • Members
  • 4,815 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:teh interwebz
  • Local time:11:50 AM

Posted 17 April 2010 - 03:47 PM

Whoa...zombie thread alert! :cool:

:thumbsup:

Ohhh....I see. I didn't know you could use text files to store commands. I had to put the full location of the text file (C:\Users\Name...etc.) in the batch file, but it worked!!

Thanks a lot, tjn1987!! :trumpet:

:inlove: to Bleeping Computer!! :flowers:
PICNIC - Problem In Chair, Not In Computer

Posted Image Posted Image

20 Things I Learned About Browsers and the Web

#4 tjn1987

tjn1987

  • Members
  • 2 posts
  • OFFLINE
  •  
  • Local time:12:50 PM

Posted 17 April 2010 - 11:43 PM

Forgot to mention about the full path. :thumbsup:

#5 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:12:50 PM

Posted 18 April 2010 - 05:44 AM

Nifty tricks :flowers: :thumbsup:
But I do not think people assign drive letters so frequently, that they have to put it on right-click context menu.

#6 keyboardNinja

keyboardNinja

    Bleepin' Ninja

  • Topic Starter

  • Members
  • 4,815 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:teh interwebz
  • Local time:11:50 AM

Posted 18 April 2010 - 01:36 PM

Well, I didn't want to put it in a right-click context menu...just in an easily run batch file (so I wouldn't have to run the commands manually in a command prompt). But the point is still the same. So yeah, it's not something the everyday PC user would need, but it solves my unique problem.

Thanks again, tjn1987!! :thumbsup:
PICNIC - Problem In Chair, Not In Computer

Posted Image Posted Image

20 Things I Learned About Browsers and the Web




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users