# Win XP USB Port?

**URL:** <https://www.ruby-forum.com/t/win-xp-usb-port/53345>\
**Category:** Ruby\
**Created:** [February 2, 2006, 12:17am UTC](https://www.ruby-forum.com/t/win-xp-usb-port/53345 "2006-02-02T00:17:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ESRSBruecklmeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e19b73/32.png) [@ESRSBruecklmeier](https://www.ruby-forum.com/u/ESRSBruecklmeier)\
**Post date:** [February 2, 2006, 12:17am UTC](https://www.ruby-forum.com/t/win-xp-usb-port/53345/1 "2006-02-02T00:17:15Z")

</div>

Good morning rubyists,

has anyone ever tried to termiante a USB device on a Win XP system from  
ruby?

best regard out of the ice

eric.

---

<div class="post-metadata">

**Author:** ![ESRSBruecklmeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e19b73/32.png) [@ESRSBruecklmeier](https://www.ruby-forum.com/u/ESRSBruecklmeier)\
**Post date:** [February 2, 2006, 5:59am UTC](https://www.ruby-forum.com/t/win-xp-usb-port/53345/2 "2006-02-02T05:59:20Z")

</div>

How’s the weather down there?

I haven’t tried, but it may be possible using the following technique.  
Let me know if you need more help doing any of the steps:

1. Using ruby dl, connect to setupapi.dll and kernel32.dll
2. Call the function CM\_Locate\_DevNode to get the device handle for  
the usb drive.
3. Call the function CM\_Request\_Device\_Eject to stop the usb device.

You’ll need to do a google search of [microsoft.com](http://microsoft.com) for each of those  
functions to know how to call them.

Dan

---

<div class="post-metadata">

**Author:** ![ESRSBruecklmeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e19b73/32.png) [@ESRSBruecklmeier](https://www.ruby-forum.com/u/ESRSBruecklmeier)\
**Post date:** [February 2, 2006, 4:06pm UTC](https://www.ruby-forum.com/t/win-xp-usb-port/53345/3 "2006-02-02T16:06:18Z")

</div>

On 2/1/06, E.-R. Bruecklmeier [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Dr. Eric-Roger Bruecklmeier  
> Electronics Engineer / Communications Officer  
> Neumayer Station Antarctica  
> 70Â°39’S 08Â°15’W

I’m officially using you as a reference in my next “Ruby/Rails is  
Viable”  
defense :

“They use in research on Antartica”

–

---

<div class="post-metadata">

**Author:** ![ESRSBruecklmeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e19b73/32.png) [@ESRSBruecklmeier](https://www.ruby-forum.com/u/ESRSBruecklmeier)\
**Post date:** [February 2, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/win-xp-usb-port/53345/4 "2006-02-02T16:48:43Z")

</div>

Peter F. schrieb:

> I’m officially using you as a reference in my next “Ruby/Rails is Viable”  
> defense :
> 
> “They use in research on Antartica”

not yet and not until the problem with the USB device is solved :-/

eric.

---

<div class="post-metadata">

**Author:** ![ESRSBruecklmeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e19b73/32.png) [@ESRSBruecklmeier](https://www.ruby-forum.com/u/ESRSBruecklmeier)\
**Post date:** [February 2, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/win-xp-usb-port/53345/5 "2006-02-02T17:31:10Z")

</div>

> not yet and not until the problem with the USB device is solved :-/

So how far have you got?

Dan Amelang

---

<div class="post-metadata">

**Author:** ![ESRSBruecklmeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e19b73/32.png) [@ESRSBruecklmeier](https://www.ruby-forum.com/u/ESRSBruecklmeier)\
**Post date:** [February 2, 2006, 6:46pm UTC](https://www.ruby-forum.com/t/win-xp-usb-port/53345/6 "2006-02-02T18:46:51Z")

</div>

Quoting “E.-R. Bruecklmeier” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Daniel A. schrieb:
> 
> > > not yet and not until the problem with the USB device is solved  
> > > :-/  
> > > So how far have you got?
> 
> I’m still looking for a posibillity to switch of a USB device out  
> of ruby.

That isn’t really a Ruby question so much as an “is there a  
library/API to do this and can I use it from Ruby?” question. (If  
the first answer is yes, the second answer is a qualified yes,  
though you might need to write a C extension.)

What specific USB device are we talking about, and what do you mean  
by “switch off”? Is this something you already know how to do from  
another language?

-mental

---

<div class="post-metadata">

**Author:** ![ESRSBruecklmeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e19b73/32.png) [@ESRSBruecklmeier](https://www.ruby-forum.com/u/ESRSBruecklmeier)\
**Post date:** [February 2, 2006, 5:40pm UTC](https://www.ruby-forum.com/t/win-xp-usb-port/53345/7 "2006-02-02T17:40:15Z")

</div>

Daniel A. schrieb:

> > not yet and not until the problem with the USB device is solved :-/
> 
> So how far have you got?

I’m still looking for a posibillity to switch of a USB device out of  
ruby.

eric.

---

<div class="post-metadata">

**Author:** ![ESRSBruecklmeier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e19b73/32.png) [@ESRSBruecklmeier](https://www.ruby-forum.com/u/ESRSBruecklmeier)\
**Post date:** [February 2, 2006, 10:36pm UTC](https://www.ruby-forum.com/t/win-xp-usb-port/53345/8 "2006-02-02T22:36:40Z")

</div>

Did you get my first reply that specified the functions you (likely)  
have to call?

Dan Amelang
