Leave a comment

Windows Powershell/VBScript to un-mount a smart phone or tablet

Thanks for reading the squadra technologies blog!

The one line of Power-shell script below un-mounts a USB cable attached Windows Portable Device (WPD) from the Windows Operating System (XP thru W8/2012):

Invoke-WMIMethod -path Win32ext_WPD -name EjectDevice -argumentList (Get-WmiObject -Class Win32ext_WPD -Namespace root/cimv2 -ComputerName . -Filter “strFriendlyName = ‘SAMSUNG-SGH-I747′”).strId

*** change ‘SAMSUNG-SGH-I747’ to the phone/tablet name you see in Windows Explorer

To have this functionality, just download and install the squadra technologies Security Removable Media Manager. (secRMM).   The WMI WPD provider that comes with the secRMM install does not need a license so you can have this functionality free of charge!

Even better yet, the device will still take a battery charge from the PC you have it attached to so your end-user can still charge their device yet cannot copy data to it.

Of course, the secRMM product does the above line with a simple checkbox and has many more powerful security features such as locking a device to a particular userId.  For a complete list of the secRMM features, you can read the introduction chapter in the secRMM Administrator Guide (online PDF).

And just in case you have not yet started playing with Powershell, here is the equivalent VBScript:

Set objWMIService = GetObject (“winmgmts:\\.\root\cimv2”)
Set colItems = objWMIService.ExecQuery (“Select * from Win32ext_WPD Where strFriendlyName = ‘SAMSUNG-SGH-I747′”)
For Each objItem in colItems
Set objWMIWPDStatic = objWMIService.Get(“Win32ext_WPD”)
Set objInParam = objWMIWPDStatic.Methods_(“EjectDevice”).inParameters.SpawnInstance_()
objInParam.Properties_.Item(“strObjectDeviceId”) =  objItem.strId
Set objOutParams = objWMIService.ExecMethod(“Win32ext_WPD”, “EjectDevice”, objInParam)
Exit For

I hope this is helpful to someone out there.  Happy scripting!
If you have any question about the script, please feel free to contact me and we can talk over a best approach.

A free two week trial of secRMM is available at Squadra Technologies.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: