Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: "Ejecting" Removable Media Devices  (Read 6918 times)

0 Members and 1 Guest are viewing this topic.

Darkon

  • Guest
"Ejecting" Removable Media Devices
« on: March 07, 2006, 05:48:22 AM »
On devices such as jumpdrives(aka flash drives or sticks), you can right click on the and click an eject command. Can anyone tell me the shell extension i can call from a batch file. I know it will involve rundll32.exe shell32.dll but im not sure of the command.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: "Ejecting" Removable Media Devices
« Reply #1 on: March 07, 2006, 06:38:11 AM »
I wasn't aware you can "eject" these devices, but this will allow you to stop the device for safe removal:

%SystemRoot%\System32\RUNDLL32.EXE shell32.dll,Control_RunDLL hotplug.dll

Good luck.  8-)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Darkon

  • Guest
Re: "Ejecting" Removable Media Devices
« Reply #2 on: March 07, 2006, 06:57:50 AM »
thank you thats sorta what i meant because if you right click on the jumpdrive it has the command "Eject" on the drop down menu

how would i actually stop the device without the user having to do anything?

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: "Ejecting" Removable Media Devices
« Reply #3 on: March 07, 2006, 04:50:20 PM »
This may help you out: DeviceEject

It's a C++ program. For help on how to run, use: DeviceEject /?

Good luck. 8-)
« Last Edit: March 07, 2006, 04:51:21 PM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Darkon

  • Guest
Re: "Ejecting" Removable Media Devices
« Reply #4 on: March 07, 2006, 06:32:38 PM »
Thanks for the help.

samanathon

  • Guest
Re: "Ejecting" Removable Media Devices
« Reply #5 on: March 11, 2006, 06:00:47 PM »
How would you go about stopping a flash drive, if you have more then one in the computer? Say, you want to stop the E: drive but leave the F: drive?
« Last Edit: March 11, 2006, 06:02:05 PM by samanathon »

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: "Ejecting" Removable Media Devices
« Reply #6 on: March 12, 2006, 06:47:18 AM »
This little script may help you out. Should have thought of this the first time around.

Code: [Select]
On Error Resume Next

CONST MY_COMPUTER = 17

strDrive = "E:\"   ' default drive/overridden if drive pass on command line

If Wscript.Arguments.Count > 0 Then
      strDrive = Wscript.Arguments.Unnamed.Item(0)
End If

Set WshShell = CreateObject("Shell.Application")
Set WshNamespace = WshShell.NameSpace(MY_COMPUTER)
Set d = WshNamespace.ParseName(strDrive)

d.InvokeVerb "E&ject"
WScript.Echo "It is now safe to remove " & strDrive & " drive"

As written, the default drive is E:. You can override this by passing the drive letter along the command line. Save the script with a vbs extension and run from the command line or call it from a batch file: cscript scriptname.vbs driveletter:\

Note: There is no built in error checking. The script will blindly attempt an eject, valid or not.

Good luck. 8-)
« Last Edit: March 12, 2006, 06:49:02 AM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

samanathon

  • Guest
Re: "Ejecting" Removable Media Devices
« Reply #7 on: March 12, 2006, 07:55:57 AM »
Would I need to change this variable:

Code: [Select]
CONST MY_COMPUTER = 17
Does this need to be the computer name? If so, can the script read that like a batch file does?

Code: [Select]
%ComputerName%

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: "Ejecting" Removable Media Devices
« Reply #8 on: March 12, 2006, 08:42:48 AM »
The MY_COMPUTER = 17 is a reference to the My Computer folder found on Windows machines. It has nothing to do with the computername variable in the environment. The script was written specifically to answer your post. You should not need to change anything.

As mentioned, if you don't pass along a drive on the command line, the script will default to the E: drive. You can override this by passing a drive parameter at run time.

Hope this helps. 8-)

The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein