VBScript Working With Mounted Drives

This instructable is by request. Many of you may recognise this from a previous instructable I had done wich was https://www.instructables.com/id/Intro_to_VB_Script_a_beginners_guide/. Well in that one techwiz24 asked me could you use this to disconnect a network drive, display a picture, and then ask to reconnect the network drive? and by network drive, I mean an external hdd.when it reconnects, I also need it to name the external hdd, like HDD1e. I can get everything except the CMD commands for it. I think you can use diskpart, but am not sure,

Well I told him I would work on it and Create a new instructable if I figured it out. Well I figured it out. So here it is. If youhaven't read my previous instructable you can find it here. https://www.instructables.com/id/Intro_to_VB_Script_a_beginners_guide/ I would suggest reading it before reading this one if you havent read it yet as most of the stuff will be the same and I wont recover the basics.

And because lemonie complained in one of my other instructables that "In wanting to display wallpapers repeatedly you make this look rather bad. Using ALT-Print Screen would show the dialogue boxes better". I decided that I would not put up any pictures that actually had anything to do with the instructable since the instructable is not a visual thing anyway and the pictures would neither harm it nor help it so why take the time to make the screan captures just so someone can complain that I didnt screen cap them correctly.

So in this one every pick will be a background wallpaper that I like and screw if it looks bad or not!!!

Step 1: Research

First thing we need to do is find out the GUID of the hard drive we want to remove. The GUID is a Globally Unique IDentifier. What this does is allows your computer to find a specific hard drive no matter what drive letter is assigned to it. An easy way to do this is to bring up a CMD window and type "MOUNTVOL"

This will bring up the help page for Mountvol. If you look to the bottum of the list it should show all available hard drives, their drive letters and thier paths.

By doing this on mine I garnered this information:
Creates, deletes, or lists a volume mount point.

path Specifies the existing NTFS directory where the mount
point will reside.
VolumeName Specifies the volume name that is the target of the mount
point.
/D Removes the volume mount point from the specified directory.
/L Lists the mounted volume name for the specified directory.

Now if you look at the bottum of the list you will see a bunch of gobbledygook that starts with \\?\volume and ends with a drive letter. This is what we need!

Ok so lets break down what we have here :
We have volume represented by \\?\volume then we have a curly bracket then a bunch of numbers, letters and dashes. The numbers letters and dashes are actually the GUID for the drive in question then we have another curly bracket then a back slash and the drive letter. So that should be easy enough to follow.
So in my computer I have
\\?\Volume{6ad2db35-4ab2-11de-964e-806d5172696f}\
C:\
this is my main hard drive for the computer
\\?\Volume{6ad2db33-4ab2-11de-964e-806d5172696f}\
D:\
Which is a dvd writer
\\?\Volume{6ad2db34-4ab2-11de-964e-806d5172696f}\
E:\
Another dvd writer
\\?\Volume{b76a1f58-662f-11de-8a61-001114cb3c76}\
F:\
A fake dvd so I can mount ISO files created my a Daemon program I have
\\?\Volume{6ad2db32-4ab2-11de-954e-806d6172696f}\
A:\
A 3.5 floppy drive.... Yes I know I know but sadly I still use them once in a great while.
\\?\Volume{c0ea045c-56fe-11de-8a5a-001111cb3c76}\
G:\
This one here is the drive in question that I want to remove

In this instance it is actually a 128meg jump drive I used for testing. This way if I buggered it up I didnt loose a hard drive or something.

Step 2: Using Mountvol

Ok now that we have the GUID we can use it to mount and unmount the drive in question

Now before we go and do all the work of writing a script we want to make sure it works and is the correct drive. g drive is the drive I am working with so mine will say g:\ however you need to put in the drive letter of the drive you are woking with. same witht he GUID, as it is unique to each drive and yours WONT be the same as mine.

We will basically just use a delet switch "/d" to delete the mount point then use mount comand to remount it using the guid as a reference to the unmounted disk.

So bring up a cmd prompt by going to run and typing cmd

at the prompt type in:mountvol g:\ /d

now when we type mountvol in the prompt all is the same except now it says: \\?\Volume{c0ea045c-56fe-11de-8a5a-001111cb3c76}\ *** NO MOUNT POINTS ***

instead of

\\?\Volume{c0ea045c-56fe-11de-8a5a-001111cb3c76}\ G:\

This is good it means we removed the one we wanted to.

Now we need to remount it

Type this at the comand prompt:mountvol g: \\?\Volume{c0ea045c-56fe-11de-8a5a-001111cb3c76}\

and then type mountvol one more time and everything should be back to the way it was

The context to reenabling the drive is as follows:The word mountvol followed by a space then the drive letter and a colon folowed by a space then a backslash backslash question mark backslash then the word volume then a open curly bracket then the GUID then a close curly bracket then a backslash

Step 3: Working With Labels

Now part of what techwiz24 asked me was when it reconnects, I also need it to name the external hdd, like HDD1e.

To do that we simply use the label command its pretty straight forward

Just bring up a command window same as last time and type:

g:

This will change your directory to g:>

Then type vol and take not of the volume label

Then just type label and whatever you want it to be called so if I wanted to name my hard drive bobby I would type:
label bobby

Then just type vol again and it will show the new name of the volume is bobby

Now that only works if you are working in the directory of the volume you want to change however when we make our script we dont want to change directory then change volume so we would just type:
label g: bobby

Told you it was petty simple.

Step 4: Adding What We Learned Into the Script

Ok so now we just make our script the way we did before but instead of using ipconfig comands we will now be using mountvol comands.

Here is the code to open a picture like he wanted and close the first command prompt window:

wscript.sleep 2000shellobj.sendkeys "c:\3.jpg{enter}exit{enter}"

_

As you can see you can add multiple commands to one line as long as the window is still open. It will wait till the last command has been executed before starting the next one.

Here is the code for the pop up boxs so your script stays running until you reenable the drive:Dim MyVarmyvar=2while myvar=2MyVar = MsgBox ("Turn drive back on", 65, "Turn drive back on")wend

msgbox("We will now Turn hard drive back on!!!")

_

Note that by making the Myvar variable = to 2 wich is the value of the cancel button on the message box we will run a continuous loop until the ok button is pressed. This forces us to click yes to end the script. Only after yes is pushed does the myval value change to 1 and allow the loop to be broken therfore continuing the script and throwing up the messagebox saying the drive will then be reenabled.

Now if you remember from before it wont do the next comand until the last command has been finished so until the ok button is pressed on the messagebox no action will be taken.

Yes we could just use the messagebox to reenable the drive but then if you dont want it enabled yet but accidently click ok there is no safeguard. With the yes/no box you have no choice but to click yes.

We could get rid of the extra messagebox but I like having a confirmation that the action is being taken.

Now we get to where the remounting, labeling and cleaning up is done. You would think well this is just straight forward but its not. If you notice every time we want to place an enter or tab key into our sendkeys line we just type {ENTER}. The reason for this is because it sees the { and } as special characters. Therefore if we use the cutrly brackets like they are printed in the guid {c0ea045c-56fe-11de-8a5a-001111cb3c76} the sendkeys command would esentually press the c0ea045c-56fe-11de-8a5a-001111cb3c76 button. Since there is no such button our script would crash and then no remounted drive for us.

So how do we get around that? Well ironically the answer is in the brackets themself. Since anything thtat is within the open and close curly brackets will esentially be sent as a pressed key we just put the bracket we want inside the open and close curly brackets. So an open would be {{} and a close would be {}}

So now the end of our code would look like this:shellobj.run "cmd"wscript.sleep 200shellobj.sendkeys "mountvol g: \\?\Volume{{}c0ea045c-56fe-11de-8a5a-001111cb3c76{}}\{enter}label g: HDD1e{enter}taskkill /F /IM rundll32.exe{enter}exit{enter}"

Step 5: The Completed Script

Here is the completed script without interuptions that you can just slide right into your script and be done with it. You must redirect the line that references the picture to a picture you want in a directory you want but remember dont use a directory on the volume you are removing or it will crash out becasue it wont find it in the directory. Also remember that you have to change the drive letters and GUID to your actual ones as these reflect mine and could possibly bugger up your system. Look fo the Rem lines before the line you need to change and you should be fine:

set shellobj = CreateObject("WScript.Shell")shellobj.run "cmd"wscript.sleep 200rem change the following line to reflect the drive letter of your driveshellobj.sendkeys "mountvol g:\ /d{enter}"wscript.sleep 2000rem change the folowing line to reflect the actual name and directory of the picture your usingshellobj.sendkeys "c:\3.jpg{enter}exit{enter}"

msgbox("We will now Turn hard drive back on!!!")shellobj.run "cmd"wscript.sleep 200rem change the GUID to your actual GUID and the drive letters (both of them)to the actual drive rem letter and the label to any label you want the drive to be labeled shellobj.sendkeys "mountvol g: \\?\Volume{{}c0ea045c-56fe-11de-8a5a-001111cb3c76{}}\{enter}label g: HDD1e{enter}taskkill /F /IM rundll32.exe{enter}exit{enter}"

Step 6: No Steps Really Just a Comment

Well I hope that helped ya.... If anything isnt explained well enough let me know and i will try to explain better. And I hope everyone liked the wallpapers. No i didnt make them.... they are all ones I have found on the net.

NOTE:: If anyone has any complaints about my instructable please forward them to getalife@quityourwhining.com. I mean seriously, do you really think I give a dang what you think? If you dont want to learn something then dont, If you do then do, but don't be a jerk and complain because the non esential pictures aren't formated correctly or whatever cause frankly I DONT CARE!!!

Organization Contest

Paper Contest

Weaving Challenge

19 Discussions

If it isn't worth doing <em>without</em> cramming it full of shiny images: don't do it. If you want to show collections of pictures dump them in a <a rel="nofollow" href="https://www.instructables.com/edit/new?type=forumTopic">Forum topic</a><br/>Screenshots might not be as exciting but they're much more appropriate, especially if you want people to <em>read</em> what you spent so much time working on.<br/><br/>L<br/>

If it isn't worth doing without cramming it full of shiny images: don't do it? Really? Seriously?
First off:
Its an instructable about how to write a script!!! You want me to take a picture of me typing at the keyboard? Would that help you understand what the script is doing in any way? How bout I take a screen capture of the notepad I am writing in that shows a blury version of the text that I already have in the text version of the instructable!!! Blury redundancey will surely explain how to do it better right? Oh, Oh, wait, how bout I take a screen capture of a pop up that you already know what it looks like from every single pop up you have ever gotten using windows. That would surely get persons reading this instructable to understand how to rite the script and understand what its doing and why. Wait I got it, I will take a screen capture of the My Computer screen showing nothing in it so you can see that the script did what it was supposed to do. That will surely help the instructable in ways that I couldnt have imagined. I mean seriously, Can you name me one screen capture I could have done that would have explained the script or more impotantly how to write a script.
I meen this is coming from someone that says to save internet energy read an encylopedia. That s all well and good if you have one at your house. I dont. Most people I know dont. Matter of fact the closest place that does is the library in chardon wich is about 15 miles away. So instead of looking it up on the web I will go outside and fire up the Dodge Durango that gets 14 miles to the gallon and drive 30 miles round trip to find out the name of the person that founded the fathers rights movement in Ohio, only to find out that the encyclopedia doesnt have that information but luckely while im at the library in it 76 degree environment brought on by central air wich is powered by electricity that is derived from the burning of fosil fuels the nice librarian says You know if you want to know the answer to that I could find out for you. So in my disgust of having made a seemingly wasted trip I agree to allow her to help me. She goes into her office in the back and moments later comes out of her office with a piece of paper with the name Robert Martin on it. Well how did You get it that fast I say ? Easy she says, I just googled it!
It would be one thing If Instructables like that were made for fun but I doubt it was, I really think you were serious. I dont really think you thought it through very well. Just like the comment about cramming it full of shiny images. I dont think you thought it through very well.
Ill tell you what. For every inteligent suggestion you give me that actually helps a person learn what I was teaching more than what I said in the instructable itself, I will make that suggested image and takedown one of the backgrounds I have.
Now to qualify It has to Improve the understanding of what is being said, not just merely show something that is vagelyu related.
So dont give me the suggestion "well a screen capture of the dos prompt showing the volume label." That will not improve any understanding at all . All that will show is a blury version of what I already copy and pasted into the text of the instructable.
Here is your chance to shine. Here is your chance to show me how to do an instructable correctly. I am basically giving you carte blanche to improve my instructable. All you have to do is show me the error in my ways and I will graciously bow to your Idea. I have no problem being told Im wrong, nor do I have a problem admitting I am wrong. So if your Idea is good I will use it and even credit you for the idea. I just have yet to find one image that shows "shellobj.sendkeys "mountvol g:\ /d{enter}"" any better than just typing it in the text area and letting them copy and paste it.
Secondly:
You said If it isn't worth doing without cramming it full of shiny images: don't do it. What would you have me do? Make an instructable with no pictures? Thats an instructables No no. And as we have already discussed there are no images that help the instructable in any way so any image I put in there is just gona be cramming it with shiny images to placate a few people that seem to think blury images of text are better than nothing.
So in yourwords since i cant do it without shiny images I shouldnt do it at all. its thinking like that that made it to where I had to learn oll of this stuff on my own with nobody else to help me. When i got stuck there was noone to say you left a period in when you shouldnt have. No i had to go through a couple hundred lines of code to find that one stupid little period out of place.
I do these because there are people that apreciate them and appreciate the help. Clearly you are not one of them people and I can understand that. But why dont you just accept the fact you dont apprecate them and move on instead of ripping on me just cause you think you could have done it better.

"You said If it isn't worth doing without cramming it full of shiny images: don't do it. What would you have me do? Make an instructable with no pictures? That's an instructables No no. And as we have already discussed there are no images that help the instructable in any way so any image I put in there is just gona be cramming it with shiny images to placate a few people that seem to think blury images of text are better than nothing. "

You said it yourself in that unnecessarily long epic. If there are no pictures that would contribute to a better understanding of the instructable, why put in pictures that have absolutely nothing to do with it? Nobody reading this cares about your pretty desktop background images, they're reading it because they want information how do this particular task.

I love how programmers are constantly battling over the binary way that all things should be. I suppose that having this binary outlook comes with the territory. I sincerely hope that my many years of programming experience have not jaded the creative side of my brain, too. I found the article enjoyable and useful until I got to this rant. As a programmer, I somehow feel compelled to contribute, as a moth to a burning tire fire.

The writer of this instrructable put in pictures that have no supporting effect and are only there to distract at best. Then he has a picture of some goofy looking guy as the final picture that looks like a cab going down the road with its doors open.

What is the difference between a picture of cab guy and the word html and a picture of say, the General Lee? Was his information in the instructable helped in any way by a capture of the left upper corner of the notepad he had open?

If your original comment of "If it isn't worth doing without cramming it full of shiny images: don't do it" is correct then are you saying the writer of the example instructable should not have written his instructable? Was the information he gave not worth anything just becasue there are no pictures he could have put in that would have helped him to relay his information better than what he already had in his text?

And as far as your 50 words or less comment, if you want 50 words read the last paragraph in the instructable and it says eveything I need to say in a nutshell. Granted its more like 65 but it does the trick... I will even copy and paste it for you so you dont have to go clicking and wasting internet energy.... it said:

NOTE::If anyone has any complaints about my instructable please forward them to getalife@quityourwhining.com. I mean seriously, do you really think I give a dang what you think? If you dont want to learn something then dont, If you do then do, but don't be a jerk and complain because the non esential pictures aren't formated correctly or whatever cause frankly I DONT CARE!!!

No obviously you are misuderstanding. I care about my instructable, I care about how it looks. I care that others try to put me down becasue they think they can do better. I care that others get helpfull information about what I am trying to say. And I care about the way others view my instructable. What I dont care about is your negative attitude nor your opinion. I dont care if you have a complaint nor what the complaint is unles it is legitimate in wich this case it is not. I dont care what you (LEMONIE) or anyone else with a view that is neither logically thought out nor inteligent thinks.
That does not meen I wont defend myself. That doesnt meen I will just sit here and take a virtual b***h slap just cause you feel like you need to put it out there.
And I think you are confusing short and concise. Concise means free of superfluous detail where short is not long. Superfulous is defined as exceeding what is sufficient or necessary. Everything I had in the message was in fact sufficient and necessary to get my point across and, therefore; does not fall under superfluous and since my statement was free of superfluous detail it, therefore; falls under thedefinition of concise. It just was not short.
But i do agree with you on what you said in your last comment about addressing YOUR SIMPLE COMMENTS. As far as I can tell most of your comments so far on this and my other instructables to date have been simple. Simple minded at least.
And dont think I havent noticed you dodging my questions either. You have basically complained then when I put questions or chalenges to you, you simply make more complaints. Is it because I am right and you dont want to admit it or is it that you jusy love complaining so much you cant think of anything else to do ?

The thing looks bad, you must appreciate that virtually all the commentary on this has been about that. Do you see what I mean by a distraction from the content which you put time into?That is the only thing I've addressed, it's the only thing that bothers me.

Notice that I don't care about your negative commentary, I am actually bothering to reply to you rather than writing you off as a ()?

You could have said: "There are no useful images which I could have added to this, but as the format requires images, I chose some that I liked. That's the way I like it. I appreciate that yourself and gavinzac are distracted by these things, but I believe other people will not be." - and leave it at that.

Instead you've taken this personally and spent a lot of time ranting against a perception rather than looking at a fair comment.

Just make this look a bit more serious about the subject and less like a boy's bedroom?

Is there a way to make the script itself learn the GUID and save it as a variable

I don't mean to annoy you because this is good, but, you could of made a batchfile so that when you want to diconnect the drive it will activate the batchfile to do that all you need is to add this in the script in the place of the keysend:

OMG, THANKYOU!!! I was using this to disconnect my external HDD so my anti virus did not scan it and take 5 days (for real), and then when it I plugged it back in, I had to remember the exact name that I had before (for networking reasons), with this script, I can do all that!!! YIPPIE

You are not supposed to upload other people's images... by uploading the images you claim them as your own and release them under the creative commons license. That is why people don't want you to upload the wallpapers (a distraction at best, IP theft at worst), and why this will most likely be removed.

Actually if you read the last page of the instructable I actually say that I lay no claim to the pictures therfore the creative commons license would therefor not apply.
And most of the ones I have up here have been released by thier creators under the understanding that they can be used freely as long as they are not used for comercial gain. Of wich I am sure I'm not gonna get paid for this instructable so I am fine.
The reason I say most and not all is because there are a couple that I got a long time ago off a wallpaper page were people just randomly uploaded images.
But to say the least, if any one is the actual owner of any piece of artwok I have up now (AND CAN PROVE IT) and is either offended that I want to share their beutiful work or wishs that I take it down I will do so without a problem. But until then I have broken no laws that I am aware of and I am violating no ones rights so it stays the way it is.
Now onto another note, why is it that some people are more infactuated with my wallpapers than what i am actually teaching in the instructable itself? Do people really care that little about this stuff that they are so bored they are just looking for something to do or what?
I mean jesus christ people, I freakin worked on this for almost an hour just on the script alone figuring stuff out, then another hour writing the instructable and then maybe 5 minutes uploading freakin pictures cause you have to have pictures on a instructable even though in this case they do abso-freakin-lutely nothing for the instructable itself and all you are interested in are the freakin pictures?
I see freakin instructables all the time where people show the dumbest stuff like how to tie your shoes wich if you are reading an instructable you already should know this or how to draw a smiley face by drawing a circle then putting two dots and a mouth wich you learn when you are like 8 months old or so but when someone puts up something that could actually help someone in any way there has to be someone that complains.
It makes it to where I just want to say to heck with it and never write another instructable again just so i dont have to deal with the narrow minded people!!!