c.haslam Posted July 24, 2018 Share Posted July 24, 2018 (edited) I have 2 PCs on a LAN. My PC has fixed drives C:, F:, G: and H:. It also has mapping to drives on the other PC. They are W:, X:, Y: and Z:. The script below suggests that mapped drives are not included in DriveGetDrive('ALL'). expandcollapse popup#include "..\cDebug no maps.au3" Global $g_oCFF_WmiDriveInfo Global $all_Drives = DriveGetDrive('ALL') AddDisconnectedDriveLetters($all_Drives) _guidebug(@ScriptLineNumber,'ALL,NETWORK,all including mapped but disconnected',DriveGetDrive('ALL'),DriveGetDrive('NETWORK'), $all_Drives) Func AddDisconnectedDriveLetters(ByRef $a_Drives) ; ref 1 If Not IsObj($g_oCFF_WmiDriveInfo) Then _CFF_GetWMIdriveInfo() EndIf Local $nuDrive, $bfound For $objItem In $g_oCFF_WmiDriveInfo If $objItem.ConnectionState = 'Disconnected' Then $nuDrive = $objItem.LocalName $bfound = False For $i = 1 To $a_Drives[0] - 1 If $a_Drives[$i] = $nuDrive Then $bfound = True ExitLoop EndIf Next If Not $bfound Then $a_Drives[0] += 1 ReDim $a_Drives[$a_Drives[0] + 1] $a_Drives[$a_Drives[0]] = StringUpper($nuDrive) EndIf EndIf Next EndFunc ;==>_CFF_AddDisconnectedDriveLetters ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __CFF_GetWMIdriveInfo ; Description ...: Collects attributes of local and mapped drives for local computer ; Author ........: c.haslam ; Remarks .......: Includes remote drives that are not currently connected ; Ref: https://www.autoitscript.com/forum/topic/71790-enum-network-connections/ ; Ref: Scriptomatic ; =============================================================================================================================== Func _CFF_GetWMIdriveInfo() ; Ref: https://www.autoitscript.com/forum/topic/71790-enum-network-connections/ ; Ref: Scriptomatic Local $host = "." Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $host & "\root\cimv2") $g_oCFF_WmiDriveInfo = $objWMIService.ExecQuery("SELECT * from Win32_NetworkConnection") EndFunc ;==>_CFF_GetWMIdriveInfo To keep the code to a minimum, it calls _GuiDebug(), part of my cDebug no maps.au3 which can be found here. It is highly stable, being in daily use. Running this script produces: ***7------------------------- ALL ALL Vector: 6 elements [0] => <Int32> 5 0x05 [1] => <String> (2 chars) 'c:' [2] => <String> (2 chars) 'd:' [3] => <String> (2 chars) 'f:' [4] => <String> (2 chars) 'g:' [5] => <String> (2 chars) 'h:' NETWORK => <String> (0 chars) '' all including mapped but disconnected all including mapped but disconnected Vector: 10 elements [0] => <Int32> 9 0x09 [1] => <String> (2 chars) 'c:' [2] => <String> (2 chars) 'd:' [3] => <String> (2 chars) 'f:' [4] => <String> (2 chars) 'g:' [5] => <String> (2 chars) 'h:' [6] => <String> (2 chars) 'W:' [7] => <String> (2 chars) 'X:' [8] => <String> (2 chars) 'Y:' [9] => <String> (2 chars) 'Z:' Should DriveGetDrive('ALL') include mapped drives? Edited July 24, 2018 by c.haslam Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
spudw2k Posted July 25, 2018 Share Posted July 25, 2018 It should, and does on my PC, at least using v3.3.14.2. If you force it to do only "Network" drives, does it return results? Are you running the script in the same privilege level that the mapped drives are connected? Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
BrewManNH Posted July 25, 2018 Share Posted July 25, 2018 Your script shows me this when I run it. Quote ***7------------------------- ALL ALL Vector: 8 elements [0] => <Int32> 7 0x07 [1] => <String> (2 chars) 'c:' [2] => <String> (2 chars) 'd:' [3] => <String> (2 chars) 'h:' [4] => <String> (2 chars) 'i:' [5] => <String> (2 chars) 'l:' [6] => <String> (2 chars) 'p:' [7] => <String> (2 chars) 'x:' NETWORK NETWORK Vector: 6 elements [0] => <Int32> 5 0x05 [1] => <String> (2 chars) 'h:' [2] => <String> (2 chars) 'i:' [3] => <String> (2 chars) 'l:' [4] => <String> (2 chars) 'p:' [5] => <String> (2 chars) 'x:' all including mapped but disconnected all including mapped but disconnected Vector: 9 elements [0] => <Int32> 8 0x08 [1] => <String> (2 chars) 'c:' [2] => <String> (2 chars) 'd:' [3] => <String> (2 chars) 'h:' [4] => <String> (2 chars) 'i:' [5] => <String> (2 chars) 'l:' [6] => <String> (2 chars) 'p:' [7] => <String> (2 chars) 'x:' [8] => <String> (2 chars) 'X:' C is the HD and D is my thumb drive, the rest are all mapped drives. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
c.haslam Posted July 25, 2018 Author Share Posted July 25, 2018 14 hours ago, spudw2k said: It should, and does on my PC, at least using v3.3.14.2. If you force it to do only "Network" drives, does it return results? Are you running the script in the same privilege level that the mapped drives are connected? This script #include "..\cDebug no maps.au3" Local $a1 = DriveGetDrive('NETWORK') _GuiDebug(@ScriptLineNumber,'Network only,@error',$a1,@error) produces ***4------------------------- Network only => <String> (0 chars) '' @error => <Int32> 1 0x01 Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Earthshine Posted July 25, 2018 Share Posted July 25, 2018 (edited) I tested it on my systems and it works great. C is SSD, D is HDD, E is DVD the rest are network Edited July 25, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
c.haslam Posted July 26, 2018 Author Share Posted July 26, 2018 Thanks. Which version of Windows you all are running? Both PCs here are running Win 7 SP1. I seem to remember reading somewhere that M$ changed when a remote drive is connected from always to on demand between XP and Win7 (probable with Vista). I think that they reverted to always connected with Win 8. At the time of the tests above, Computer > Network was showing, for W: thru Z:, Disconnected Network Drive. I am investigating further. Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Earthshine Posted July 26, 2018 Share Posted July 26, 2018 windows 10 and 2008r2 sp1 with updates My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
BrewManNH Posted July 26, 2018 Share Posted July 26, 2018 They probably won't show if they're not connected. Because at that point they're not there, you have to be able to access them. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
c.haslam Posted July 26, 2018 Author Share Posted July 26, 2018 (edited) OK. So how should I connect to mapped drives, and to unmapped shareable drives? This function connects to mapped drives, but probably does so by remapping to the same drive letter as my Windows already has: Func _CFF_ConnectMappedDrive($sDrive) If Not IsObj($g_oCFF_WmiDriveInfo) Then _CFF_GetWMIdriveInfo() EndIf For $objItem In $g_oCFF_WmiDriveInfo If $objItem.ConnectionState = 'Disconnected' And $objItem.LocalName = $sDrive Then ; persistent,Show authentication dialog if required DriveMapAdd($objItem.LocalName, $objItem.RemoteName, 1 + 8) ExitLoop EndIf Next EndFunc ;==>_CFF_ConnectMappedDrive with Global $g_oCFF_WmiDriveInfo ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __CFF_GetWMIdriveInfo ; Description ...: Collects attributes of local and mapped drives for local computer ; Author ........: c.haslam ; Remarks .......: Includes remote drives that are not currently connected ; Ref: https://www.autoitscript.com/forum/topic/71790-enum-network-connections/ ; Ref: Scriptomatic ; =============================================================================================================================== Func _CFF_GetWMIdriveInfo() ; Ref: https://www.autoitscript.com/forum/topic/71790-enum-network-connections/ ; Ref: Scriptomatic Local $host = "." Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $host & "\root\cimv2") $g_oCFF_WmiDriveInfo = $objWMIService.ExecQuery("SELECT * from Win32_NetworkConnection") EndFunc ;==>_CFF_GetWMIdriveInfo Perhaps there is a better way. I do not know how to connect to un-mapped drives. I am looking for what FileSelectFolder does in Network > other PC where other PC has access to shareable drives on this PC, but has no mapped drives. Edited July 27, 2018 by c.haslam Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now