Solved

Follow up question to ID 40605568

Posted on 2015-02-12
22
98 Views
Last Modified: 2015-02-13
I should have asked this before closing above question.
I am constantly connecting and disconnecting various external drives to my computer (one at a time) - which is always "Drive F".  I find it very annoying to have to stop what I am doing and look for the little icon in the system tray that allows to "Safely remove Hardware and remove Media".

Could someone help me create a script that would do that using AutoHot keys? Thanks
0
Comment
Question by:camtz
  • 11
  • 7
22 Comments
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40605907
Hi Carlos,

I can't find question ID 40605568 — please post a URL to it.

Re this question, I suggest using the RemoveDrive command line utility:
http://www.uwe-sieber.de/drivetools_e.html

When you download the zip file, you'll see that there are 32-bit and 64-bit versions. Extract the right one for your version of Windows and put it in whatever folder you want, such as C:\MyProgs, in which case the command to Safely Remove drive F would be:

C:\MyProgs\removedrive.exe F: -L

The -L parameter means that it will try to to remove the drive in a loop until it is successful (shows "Success" in green) or until it is cancelled/failed (shows "Failed" in red).

Decide on a key or key combo to invoke this. Let's say you decide on Alt-Ctrl-R (for Remove). Then put this in your AutoHotkey macros script:

!^r::
Run,"C:\MyProgs\removedrive.exe" "F: -L"
Return

That should do it. Regards, Joe
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40606006
Hi Qlemo,
Thanks for that comment, but note that even having the Question ID is not helpful in locating a question, as EE's Search and Advanced Search functions cannot search by Question ID. This has been reported in the New Launch project:

http://www.experts-exchange.com/PRI_3525.html
http://www.experts-exchange.com/PRI_6885.html

That's why I asked Carlos for the URL. Regards, Joe
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40606039
Qlemo,
That's an excellent idea! I didn't know that you can ignore the Topic path. In other words, this:

http://www.experts-exchange.com/Q_28615686.html

actually takes you to this:

http://www.experts-exchange.com/Programming/Misc/Q_28615686.html

Very nice! Thanks, Joe
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40606055
What's the link to your article?
0
 

Author Comment

by:camtz
ID: 40606581
Olemo, thank you for that.  I'll know in the future.  Joe, sorry to give you the bad news but this is not working for me.  Look at the pics and see if I've done anything wrong. Pic 1Pic 2Pic 3Pic 4Pic 5Pic 6
The only time I saw the window was when I used your suggestion.  In all other cases, the black window would show up momentarily and disapier.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40606764
I think the problem is that your AHK script has this:

Run,"C:\My Documents\My Programs\RemoveDrive" "F: -L"

Based on the screenshot you posted, it should be this:

Run,"C:\Users\Home\Documents\My Programs\RemoveDrive.exe" "F: -L"

Copy/paste the line above into your script (instead of the Run statement you have) and I think it will work. If that doesn't work, made a root folder on your C drive called MyProgs and put RemoveDrive.exe in there. Then copy/paste this line into your script:

Run,"C:\MyProgs\RemoveDrive.exe" "F: -L"

Btw, I never use the Documents, My Documents, My Music, My Pictures, My This and My That thingies in Windows, so I'm not an expert on how that works. I simply store all of my files on my J: drive in folder names of my choosing. But it seems that the problem with your script is that AutoHotkey can't find the RemoveDrive.exe file in order to run it, and I suspect it has something to do with the path to it. I'm sure that putting your AHK scripts in a folder of C: (or any other drive) will work fine. All of my AHK scripts (including my hotkeys script, which runs from the Startup group) are stored in a folder called J:\bats (where all of my batch files, AHK scripts, REXX scripts, and other scripts are stored). I'm sure you can achieve the same with Documents/My Documents, but I'm not very familiar with that. Regards, Joe
0
 

Author Comment

by:camtz
ID: 40608232
Dear Joe, I created a root folder in C:\ as you suggested but it didn't fix the problem.  Now I know what the black box was trying to tell me.  It comes and goes so fast that it took two of us to take a picture with my cell phone.  The problem seems to be that it considers Drive F  "an invalid" drive rather than it can't find it. Please look at the pic which shows the description of this Drive under "My Computer"  ( Pic 2 above) and tell me if we should modify the description of Drive F with more specificity. Thanks
0
 

Author Comment

by:camtz
ID: 40608240
2015-02-13-10.31.35.jpgSorry, forgot picture.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40608357
Let's forget AutoHotkey for now — we'll worry about that later. Just open up a command prompt and issue this command:

dir f:

That will tell us if drive F exists. If it doesn't, that's the problem. If it does, then navigate to the folder where  RemoveDrive is and type in the command:

removedrive.exe F: -L

Note that there's a space between the colon and the hyphen. What happens when you issue this command?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40608580
Carlos,
I haven't heard back from you on my last post, but if you can't get RemoveDrive.exe to work, here's a different idea that uses just an AutoHotkey script — no need for another utility. First, get the script from here:

http://ahkscript.org/boards/viewtopic.php?f=6&t=4491

In the code block at the top of that post, click Select All and then Ctrl-C (Copy). Then paste it (Ctrl-V) at the bottom (after the last Return) of your AHK script that has your hotkeys defined. Then add this new hotkey in your hotkeys script:

^]::
Eject("F")
If (ErrorLevel=0)
  Return
Msgbox,4112,Error,ErrorLevel=%ErrorLevel% trying to eject F drive
Return

Open in new window


I just tested it here in W7/64-bit with the latest AHK release — it works perfectly! It displays the error MsgBox only in the case where the Eject failed (for example, if the F drive doesn't exist, in which case you'll see an ErrorLevel of -1). Regards, Joe
0
 

Author Comment

by:camtz
ID: 40608779
Sorry, I was tied up on something else.  I went to command line and sending pic of results.  Note that it states the name is EXTRA.  Copied and pasted your script and sending a pic of that as well. I don't know where the folder for this is.  I just go to the bottom of the task bar on the right and pull up a window that contains icons of things that are running , select the one that says Safely Remove ... and click on it which releases the drive. PIC 10Pic 11
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40608809
Carlos,
The "Call to nonexistent function" error means that you didn't copy/paste the Eject source code into the bottom of that file. What you were supposed to do is in my last post, but I'll repeat here what you need to do:

(1) Go to:
http://ahkscript.org/boards/viewtopic.php?f=6&t=4491

(2) Click Select All in the code block at the top (pointed to by red arrow in this screenshot):
Select all
(3) Hit Ctrl-C (that copies the code to the clipboard).

(4) Open your AutoHotkey.ahk file — the one you posted above showing lines 53-86. Go to the bottom of that file, which should have Return as the last line. Add a new line and then hit Ctrl-V. This will paste the Eject source code into the file. Save the modified file.

(5) Reload the modified script — right-click on its icon in the system tray and select Reload This Script.

I guarantee that if you follow these steps, it works. Regards, Joe
0
 

Author Comment

by:camtz
ID: 40608897
You are right, I did not follow your instructions correctly.  I just put the script that you said I needed AFTER installing the long script from the site.  Well, this time I did that.  Selected all, pasted it at the bottom of my list after return and pasted your script again.  I don't know if I have the latest update for AHK (that could be the problem) but this is what I got now - see picPic 12
0
 
LVL 51

Accepted Solution

by:
Joe Winograd, EE MVE earned 500 total points
ID: 40608933
ErrorLevel of -1 means that it's an invalid drive letter, i.e., the F drive doesn't exist. Maybe you had already ejected the F drive before running the script. Connect the disk drive, make sure it's there as drive letter F (do a dir F: or look in Windows Explorer for it), and then try Ctrl-] again to eject it. Btw, what version and bit-level of Windows are you using?
0
 

Author Comment

by:camtz
ID: 40609005
WOW !!! Found out what is going on.  I was looking at my computer where all the drives are displayed and when I invoked the command, the F drive DISAPPEARED from the screen.  I then went down to see if it was on the icon on the system tray and GONE.  I didn't get the green or red light etc. but I think we are finally there.  I am sending you a pic regarding the version I am running.  I want to express my appreciation for alll the hard work you put into this and also about telling me about the root folder you set up in C:\ drive.  I tried it and think it's a great idea.Pic-13.JPG
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40609043
> when I invoked the command, the F drive DISAPPEARED from the screen

Great! That means it is working!

> I then went down to see if it was on the icon on the system tray and GONE.

Great again! Exactly what is supposed to happen.

> I didn't get the green or red light

That's a feature of RemoveDrive, not of Eject. Since you switched from using RemoveDrive to using Eject, you won't be getting the green/red indicator. The way it is coded now, you won't get anything if it succeeds; you'll get the Error dialog box that you posted if it fails. But if you'd like to get a message when it is successful, change your hotkey definition to this:

^]::
Eject("F")
If (ErrorLevel=0)
  MsgBox,4160,Success,Successfully ejected F drive
Else
  MsgBox,4112,Error,ErrorLevel=%ErrorLevel% trying to eject F drive
Return

Open in new window

> I think we are finally there.

Yes, I agree!

> I am sending you a pic regarding the version I am running.

It's good to see that you are on W7 Pro 64-bit. That's also what I use on my primary machine.

> I want to express my appreciation for all the hard work you put into this

You're very welcome — happy to help!

> I tried it and think it's a great idea.

I'm glad you like it.

Regards, Joe
0
 

Author Closing Comment

by:camtz
ID: 40609062
Excellent help.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40609068
Thanks for the kind words — I appreciate it!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now