;; ;;=====================================================================================----- ;; ;;FUNCTION WMIMappedDrives() ;; ;;ACTION Return a list of mapped drives from a computer ;; ;;AUTHOR Glenn Barnas ;; ;;VERSION 1.0 - 2008/03/24 ;; ;;HISTORY 1.0 - 2008/03/24 - Initial Release ;; ;;SYNTAX WMIMappedDrives([, AuthPtr]) ;; ;;PARAMETERS AuthPtr - OPTIONAL - Object ;; - The pre-authenticated WMI object pointer. ;; Use WMIAuthenticate() udf to create the AuthPtr value. ;; AuthPtr is not needed if user has admin rights. ;; ;;REMARKS By default, returns a detailed list of all mapped drives from the ;; local computer. ;; ;; ;;RETURNS Array of drive letter / UNC Path arrays ;; ;;DEPENDENCIES WMI, ;; ;;TESTED WITH W2K, WXP, W2K3, Vista, x64 ;; ;;EXAMPLES ; Function WMIMappedDrives(OPTIONAL $_pAuth) Dim $_objWMIService, $_colItems, $_objItem ; WMI object vars Dim $_Line ; line string Dim $_aTmp[0], $_I ; return array, index Dim $_ ; temp var $_I = -1 ; If a pre-authenticated WMI object pointer was provided, use it, otherwise create a new object pointer If $_pAuth $_objWMIService = $_pAuth Else $_objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2') If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf EndIf ; get the collection of process objects $_colItems = $_objWMIService.ExecQuery("Select * from Win32_MappedLogicalDisk",,48) If @ERROR $_colItems = 0 Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf ; Enumerate the collection of process data For Each $_objItem in $_colItems $_I = $_I + 1 ReDim Preserve $_aTmp[$_I] $_aTmp[$_I] = $_objItem.Name, $_objItem.ProviderName Next ; return the array, close the collection, and gripe if no items were found $WMIMappedDrives = $_aTmp $_colItems = 0 Exit 0 EndFunction