Page 1 of 1

Just List Devices - Created 01/09/2013

Posted: Sun Sep 01, 2013 3:45 pm
by trixmoto
This report, as requested, lists all of the active devices in a textfile. It was built specially to someone's specifications, but I've finally got round to releasing it to the community. You need to be on MM build 1627 at least for this to work.

The installation package can be downloaded from my website. Or here is the code for your perusal...

Code: Select all

'
' MediaMonkey Script
'
' NAME: JustListDevices 1.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 15/03/2013
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' NOTE: Mask can include fields... <ID><Instance><Drive><Name><Caption><Handle>
'
' [JustListDevices]
' FileName=JustListDevices.vbs
' ProcName=JustListDevices
' Order=1
' DisplayName=Just List Devices
' Description=Just List Devices
' Language=VBScript
' ScriptType=1
'

Option Explicit

Dim Mask : Mask = "<ID>,<Instance>,<Drive>,<Name>,<Caption>,<Handle>"

Sub JustListDevices 
  Dim fil : fil = "VID"
  If SDB.VersionBuild > 1627 Then
    fil = ""
  End If
  Dim list : Set list = SDB.Device.ActiveDeviceList(fil)
  If list.Count = 0 Then
    Call SDB.MessageBox(SDB.Localize("No active devices."),mtError,Array(mbOk))
    Exit Sub
  End If
  
  Dim fso : Set fso = SDB.Tools.FileSystem
  Dim path : path = Script.ScriptPath&".txt"
  Dim fout : Set fout = fso.CreateTextFile(path,True) 
  Dim Progress : Set Progress = SDB.Progress 
  Progress.MaxValue = list.Count
  Progress.Text = SDB.Localize("Exporting...")
  
  Dim i : i = 0
  For i = 0 To list.Count-1 
    Dim indx : indx = list.DeviceID(i)
    Dim sqls : sqls = "SELECT DeviceCaption FROM Devices WHERE DetailedUSBID LIKE '%"&indx&"%'"
    Dim iter : Set iter = SDB.Database.OpenSQL(sqls)
    If Not iter.EOF Then
      Dim inst : inst = list.DeviceInst(i)
      Dim driv : driv = "?"
      If list.DriveLetterIndex(i) > -1 Then
        driv = Chr(list.DriveLetterIndex(i)+64) 
      End If
      Dim name : name = list.FriendlyName(i)
      Dim capt : capt = iter.StringByIndex(0)
      Dim hand : hand = "-1"
      If SDB.VersionBuild > 1627 Then
        hand = list.DeviceHandle(i)
      End If
        
      Dim str : str = Mask
      str = Replace(str,"<ID>",indx)
      str = Replace(str,"<Instance>",inst)
      str = Replace(str,"<Drive>",driv)
      str = Replace(str,"<Name>",name)
      str = Replace(str,"<Caption>",capt)
      str = Replace(str,"<Handle>",hand)
      Call fout.WriteLine(str)
    End If
    Set iter = Nothing
    
    Progress.Increase
    SDB.ProcessMessages
    If Progress.Terminate Then 
      Exit For 
    End If 
  Next 

  Call fout.Close()
  If Not Progress.Terminate Then 
    Dim WShell : Set WShell = CreateObject("WScript.Shell")
    i = WShell.Run(Chr(34)&path&Chr(34),1,0)
  End If 
End Sub 

Sub Install()
  Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
    inif.StringValue("JustListDevices","Filename") = "JustListDevices.vbs"
    inif.StringValue("JustListDevices","Procname") = "JustListDevices"
    inif.StringValue("JustListDevices","Order") = "1"
    inif.StringValue("JustListDevices","DisplayName") = "Just List Devices"
    inif.StringValue("JustListDevices","Description") = "Just List Devices"
    inif.StringValue("JustListDevices","Language") = "VBScript"
    inif.StringValue("JustListDevices","ScriptType") = "1"
    SDB.RefreshScriptItems
  End If
End Sub