Jump to content

Ipod Ejector


spudw2k
 Share

Recommended Posts

Here's a script I made to eject ipods.

user: Neoborn made a script that does this too, but his requires the use of DevEject.exe......Mine's standalone. :)

Detects the ipod via WMI and Ejects it via a Shell Object. Check it out.

$strDeviceID = ""
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\localhost\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select DeviceID from Win32_DiskDrive Where (Caption like " & chr(34) & "%ipod%" & chr(34) & ")")
For $objItem in $colItems
    $strDeviceID = $objItem.DeviceID ;DeviceID of the ipod
Next

If $strDeviceID = "" then Exit

$strDeviceID = StringRight($strDeviceID,(StringLen($strDeviceID)-4)) ;Formating

$colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDriveToDiskPartition")
For $objItem in $colItems
    If StringInStr($objItem.Antecedent,$strDeviceID) <> 0 then 
        $strPartition = $objItem.Dependent ;Partion Map 
    EndIf
Next

$colItems = $objWMIService.ExecQuery("Select * from Win32_LogicalDiskToPartition")
For $objItem in $colItems
    If StringInStr($objItem.Antecedent,$strPartition) <> 0 then 
        $strLogicalDrive = $objItem.Dependent ;Logical Drive Letter
    EndIf
Next

$strDriveLetter = StringRight($strLogicalDrive,3) ;Formatting
$strDriveLetter = StringLeft($strDriveLetter,2)   ;Formatting


$shell = ObjCreate("Shell.Application")

$objDrives = $Shell.NameSpace(17)

For $objDrive in $objDrives.Items
    If StringInstr($objDrive.Name,$strDriveLetter) <> 0 Then
        $objDriveItem = $objDrive
    EndIf
Next

if not isobj($objDriveItem) then Exit
    
For $verb in $objDriveItem.verbs
    if $verb.Name = "E&ject" Then $verb.doit
Next
Edited by spudw2k
Link to comment
Share on other sites

  • 1 year later...

Erm..is there any different between ejecting Ipod and common USB drive?

Not really. :P Except there is a difference between ejecting and "safely removing" (even though that's not what you asked).
Link to comment
Share on other sites

Very nice. You should make a way we can interface with it, without iTunes. That would open up so many possibilities.

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

Very nice. You should make a way we can interface with it, without iTunes. That would open up so many possibilities.

Interface with the Ipod? That's way beyond my current coding skills. :P I'd like to one day. Perhaps one day I could attempt to build a UDF to interface with the IPod DB, but I have a feeling this would be a great starting place for anyone. link broken. :( Edited by spudw2k
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...