http://www.perlmonks.org?node_id=1025924


in reply to Windows Net Use

The output of "net use" is generally bad to parse. If your Windos is new enough (XP Pro) to include WMIC, the output of

WMIC NETUSE LIST FULL /FORMAT:CSV
should contain all that you need, and is much easier to parse. Only problem would be share names with commas in them, but for a reason unbeknownst to me, these are much rarer than those with embedded spaces :-)

There are several such command line utilities whose output is inconsistent or not parseable without mind reading capabilities. In such cases one should look for alternative sources of input.

Replies are listed 'Best First'.
Re^2: Windows Net Use
by Anonymous Monk on Mar 28, 2013 at 11:22 UTC

    Parsing the output of WMIC looks even more difficult , cause its output is very different as compared to net use. So If u could tell me how to parse it or break it into what i need, it would be a great help..

      The suggested code will return the information in CSV format. Save it to a file and use something like Text::CSV to read only the columns you want.

      Update: use something like /output:c:\netuselist.csv to save the file.

      For the human eye it looks more gibberish, but for parsing it is less error prone.

      As marto already pointed out, the best solution is Text::CSV. Since CSV means "comma separated values", the second best is splitting on the commas.

      The first line that WMIC outputs, BTW, contains the field names.