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.