Jump to content

Getting results from net use and parsing text


Recommended Posts

I need to check if a network share is mapped or not. The idea I got is to run a command "net use" and then parse the resulting text to find out if my network share is mapped or not. For example, here is a result for net use command:

Quote

 

Status       Lokal     Remote                    Netzwerk

-------------------------------------------------------------------------------
             F:        \\192.168.100.23\share1 Microsoft Windows Network
             G:        \\192.168.100.23\share2 Microsoft Windows Network

 

I can search for a string "\\192.168.100.23\share1" to find if the share is already mapped or not.

I need this method for searching because, I do not know in advance which Drive Letter is used for the network share. Also it is possible that the network share is mapped without a drive letter.

Can anybody help, how I can run "net use" command and get the result in a text buffer so that I can parse it? I do not want to create a temporary text file (like net use >> c:\temp.txt) and then parse the text file.


A different question but related. Is there an easy method in Autoit to get the drive letter for a network share which has been mapped?

Thanks!

Link to comment
Share on other sites

Why not use DriveGetDrives along with DriveMapGet?

Local $aNetworkDrives = DriveGetDrive("Network")
    If @error Then MsgBox(4096, "Error", "No Network Drives found.")
For $i = 1 To $aNetworkDrives[0]
    MsgBox(0, "Drive " & StringUpper($aNetworkDrives[$i]), StringUpper($aNetworkDrives[$i]) & " mapped to: " & DriveMapGet($aNetworkDrives[$i]))
Next

 

Edited by Subz
Added simple example
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...