Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unplug USB device

74 views
Skip to first unread message

Jonas Sackerud

unread,
Apr 6, 2004, 8:15:59 AM4/6/04
to
Hoping that someone can help a novice with unplugging a USB device
automatically using VBScript (or any other technique for that matter).

My issue is this:

I'm using a USB hard drive for replicating my backup data from a Win2003 SBS
machine. Whenever a plug the hard drive to the computer the replication
starts using robocopy.exe from Windows Resource Kit.

If I could manage to automatically unplug the USB hard drive when
replication is finished I got myself a fully automatic process. Equal
functionality to a tape solution but with so much more space capacity :D

--
Regards - Jonas Sackerud


[MS] Scott McNairy

unread,
Apr 6, 2004, 1:21:44 PM4/6/04
to
You can accomplish this with a script:

dim bDone
bDone = false

set oQuerySink = wscript.createObject("wbemscripting.SWbemSink", "SINK_")
set NVS = createObject("WbemScripting.SWbemNamedValueSet")
set oContext = createObject("WbemScripting.SWbemNamedValueSet")

set svc = getObject("winmgmts:root\cimv2")
svc.Security_.AuthenticationLevel = 4

svc.ExecNotificationQueryAsync oQuerySink, "Select * From
win32_processStopTrace where processName = 'robocopy.exe'", "WQL", 0, NVS,
oContext

do while not bDone
wscript.sleep 1000
loop

set oContext = nothing
set NVS = nothing
set oQuerySink = nothing

sub SINK_OnObjectReady(obj, oContext)

wscript.echo obj.ProcessName

end sub

sub SINK_OnCompleted(hResult, oErr, oContext)
wscript.echo "OnCompleted for the query sink hr = 0x" & hex(hResult)
bDone = true
end sub

--
[MS] Scott McNairy
WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"Jonas Sackerud" <jonas.s...@seaflex.net> wrote in message
news:%23Kf2FC9...@TK2MSFTNGP12.phx.gbl...

Jonas Sackerud

unread,
Apr 7, 2004, 5:43:10 AM4/7/04
to
Please forgive my ignorance... where in the script is the USB device
unplugged?

Thanks for the sample code Scott. I've already written the functionality I
need for replication using robocopy.exe. All I need is the code to unplug
the USB device.

Thanks in advance - Jonas Sackerud

"[MS] Scott McNairy" <sco...@online.microsoft.com> skrev i meddelandet
news:4072e78d$1...@news.microsoft.com...

[MS] Scott McNairy

unread,
Apr 7, 2004, 1:54:32 PM4/7/04
to
Sorry this is not possible via WMI currently, assuming that by Unplugged you
mean disabling the USB device. However if it was a share on another
computer you could delete the connection to that share.

--
[MS] Scott McNairy
WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"Jonas Sackerud" <jonas.s...@seaflex.net> wrote in message

news:eqHFXRIH...@TK2MSFTNGP12.phx.gbl...

Jonas Sackerud

unread,
Apr 13, 2004, 4:55:08 AM4/13/04
to
Yes, by unpluuging I mean disabling the device. Too bad that WMI doesn't
support this. Is it not possible to interact with the application showing in
the systray that handles unplugging of USB devices then (the green fellow
with an arrow)?

It would be so smooth to get this working, plug in the USB harddrive and
replication starts - when finished the USB drive is disabled and ready to be
moved offsite.

"[MS] Scott McNairy" <sco...@online.microsoft.com> skrev i meddelandet

news:4074...@news.microsoft.com...

[MS] Scott McNairy

unread,
Apr 13, 2004, 4:16:17 PM4/13/04
to
I know what you are talking about but I am not the expert here. Anyone else
know where to go?

--
[MS] Scott McNairy
WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"Jonas Sackerud" <jonas.s...@seaflex.net> wrote in message

news:uG0OaSTI...@tk2msftngp13.phx.gbl...

Pascual Guevara

unread,
Apr 26, 2004, 6:20:13 AM4/26/04
to
I am very interested in your request because I working in a project that in
some way is similar to yours, so please, may you let me know if you get any
solution or clue? I keep on investigating too so I will do the same if I
find anything interesting.

Thanks in advance


"Jonas Sackerud" <jonas.s...@seaflex.net> escribió en el mensaje
news:uG0OaSTI...@tk2msftngp13.phx.gbl...

0 new messages