Jump to content
c.haslam

How to connect to disconnected network drives using AutoIt

Recommended Posts

c.haslam

Computer A has several drives mapped to drives on computer B.

Both computers are startup each morning, computer A first.

In Start > Computer (Windows Explorer) on A, the mapped drives initially show as Disconnected Network Drive. After running a script that executes FileSelectFolder(), and choosing a mapped drive, Start > Computer shows that drive as Network Drive.

But I am trying to help Melba23 to extend the functionality of his ChooseFileFolder.au3 to do what FileSelectFolder does:

  1. show disconnected mapped drives
  2. allow the user to choose a mapped drive, even if disconnected, i.e. connect to it.

I have found a script on the forum that finds mapped drives, even if they are disconnected:

; Ref: https://www.autoitscript.com/forum/topic/71790-enum-network-connections/

; Ref: https://stackoverflow.com/questions/22963357/explain-vbscript-wmi-query-impersonationlevel-etc#22964203

Local $host = "."
Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $host & "\root\cimv2")
Local $colItems = $objWMIService.ExecQuery ("SELECT * from Win32_NetworkConnection")
Local $conn = 0
For $objItem in $colItems
    $conn += 1
    Local $info = "Name: " & $objItem.Name & @CRLF & "ConnectionState: " & $objItem.ConnectionState & @CRLF _
        & "ConnectionType: " & $objItem.ConnectionType & @CRLF & "LocalName: " & $objItem.LocalName & @CRLF _
        & "RemotePath: " & $objItem.RemotePath
    msgbox(0,"MAP " & $conn,$info)
Next

So it is now possible to add disconnected network drives that are mapped to ChooseFileFolder.au3.

The next step is to connect to one of these drives. How does one connect to a mapped drive?


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
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

×