Jump to content
VijaySaibola

Getting results from net use and parsing text

Recommended Posts

VijaySaibola

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!

Share this post


Link to post
Share on other sites
Subz
Posted (edited)

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

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

×