Sign in to follow this  
Followers 0
gcue

net use - getting status of network drives

26 posts in this topic

#1 ·  Posted (edited)

I am trying to capture the status, if any, for each of the drives. Sometimes the Status shows "Disconnected" and sometimes it shows "OK". I am not sure if there are any other status codes other than "Disconnected" and "OK".

(by the way this status is different than the one reported by DriveStatus)

I know this is a job for stringregexp so here's what I've tried so far (but am having trouble getting the right results):

$matches = StringRegExp($output, "(?s)[v]+", 1) ;trying to seperate each line to isolate the drive mappings + status codes
_ArrayDisplay($matches)

here's the output I am trying to get statuses from:

New connections will be remembered.

Status Local Remote Network

-------------------------------------------------------------------------------

J: flinchteamsITGGSD

Microsoft Windows Network

P: flinchapps Microsoft Windows Network

R: flinchteams Microsoft Windows Network

S: flinchTempSpace Microsoft Windows Network

U: flinchuserssmith Microsoft Windows Network

OK Y: AgentSoftware DeliveryPrograms

Microsoft Windows Network

OK Z: idk01teamsdirectory Microsoft Windows Network

The command completed successfully.

many thanks in advance!!! Edited by gcue

Share this post


Link to post
Share on other sites



Hi, gcue. Are you just looking for a pop up? If so, you could always do something like this:

#include <Constants.au3>

$net = Run(@ComSpec & " /c net use", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
    $line = StdoutRead($net)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

no i already have that.. thats how i got $output =)

im trying to get the status of each drive.- thanks though

Share this post


Link to post
Share on other sites

I'm no help then :) Unfortunately, we use DFS here, which removes the Status field altogether.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Have you tried the DriveStatus command?

Share this post


Link to post
Share on other sites

hi jazzyjeff,

"(by the way this status is different than the one reported by DriveStatus)"

thanks tho

Share this post


Link to post
Share on other sites

I think that the "net use" command as you're using it just returns disconnected and ok for the network drive. It won't return drives that have been manually disconnected, and probably won't return anything for drives deleted using DriveMapDel. If you're looking for something more, we'd need to know what it is you're looking for so that we can help.


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 Gude
How 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

Share this post


Link to post
Share on other sites

actually im using the presence of a status to indicate that the drive is a custom drive mapping - otherwise its a drive mapped by AD

Share this post


Link to post
Share on other sites

You can look in the registry to see if it's a manually mapped drive by looking in HKCUNetwork and seeing if the drive letter is there as a subkey. I have for instance an I drive which is manually mapped and I have a subkey HKCUNetworkI for that drive.


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 Gude
How 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

Share this post


Link to post
Share on other sites

not in our case - prob with the way we are mapping through AD, in the registry both types of drives look the same.

this was the only way we could see to differentiate =)

Share this post


Link to post
Share on other sites

Are you using AD or a log in script to map 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 Gude
How 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

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

AD - its not a login script eiither. its done through a GPO - definitely out of my reach to modify unfortuantely.

is stringregexp able to sort out drives that have status codes?

Edited by gcue

Share this post


Link to post
Share on other sites

Are you using Server 2008 as the DC for administering GP? If you're not then it's being mapped through a log in script, or it's being set as the homedrive in AD. AD only sets up the homedrive, it doesn't have the capacity to map other 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 Gude
How 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

Share this post


Link to post
Share on other sites

not sure how its being done or what server version we are using. anyway this is the only way we can determine the difference between custom mapped drives and gpo mapped ones.

Share this post


Link to post
Share on other sites

I am trying to capture the status, if any, for each of the drives. Sometimes the Status shows "Disconnected" and sometimes it shows "OK". I am not sure if there are any other status codes other than "Disconnected" and "OK".

I know this is a job for stringregexp so here's what I've tried so far (but am having trouble getting the right results):

$matches = StringRegExp($output, "(?s)[v]+", 1) ;trying to seperate each line to isolate the drive mappings + status codes
_ArrayDisplay($matches)

Regex is great if you know how to use it. :)

I'm guessing you are collecting the output one line at a time.

Why don't you just check each line as it comes in for a "Disconnected" or "OK" and build your array from that?

You could even add a lcheck for : in the line if you think there maybe status that you arn't aware of.

Seems line the simplest (without regex) way of doing it.

Good Luck!

John Morrison

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

good idea storme =)

i have this (still think its a bit dirty but works - only identifies the GPO mapped drives but by process of elimination i can figure the other ones out?):

#include <Constants.au3>
#include <array.au3>

$output = Run(@ComSpec & " /c net use", @SystemDir, @SW_HIDE, $STDOUT_CHILD)

Local $line, $gpo_mapped_drives[1]

While 1
    $line = StdoutRead($output)
    If @error Then ExitLoop

    If $line <> "" And StringInStr($line, "") <> @error Then
        $line = StringStripWS($line, 8)

        If StringInStr(StringLeft($line, 2), ":") <> @error Then
            ReDim $gpo_mapped_drives[UBound($gpo_mapped_drives) + 1]
            $gpo_mapped_drives[UBound($gpo_mapped_drives) - 1] = StringLeft($line, 2)
        EndIf
    EndIf
WEnd

_ArrayDisplay($gpo_mapped_drives)
Edited by gcue

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

That code works for you? Because when I ran it, I get nothing in the _ArrayDisplay output even though I have a mix of manually added network drives and an AD added drive on this system.

The drive letter isn't in the first position of the $line string, on my system it's in the 3rd character position and the colon is in the 4th character position because of the OK before it.

EDIT: By the way, that code doesn't correctly identify drives mapped manually or by AD, it only identifies that they're network drives.

Edited by BrewManNH

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 Gude
How 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

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

it did work, but ive refined it to show all the mappings and label them

#include <Constants.au3>
#include <array.au3>

$output = Run(@ComSpec & " /c net use", @SystemDir, @SW_HIDE, $STDOUT_CHILD)

Local $line, $array[1], $array2[1]

While 1
    $line = StdoutRead($output)
    If @error Then ExitLoop

    If $line <> "" And StringInStr($line, "") <> @error Then
            ReDim $array[UBound($array) + 1]
            $array[UBound($array) - 1] = $line
    EndIf
WEnd

for $x = 1 to UBound($array)-1
    $line = StringStripWS($array[$x], 1+4)

    $split = StringSplit($line, chr(32))

    for $y = 1 to UBound($split)-1
        if StringInStr($split[1], ":") <> @error Then
            ReDim $array2[UBound($array2)+1][2]

            $array2[UBound($array2)-1][0] = $split[1]
            $array2[UBound($array2)-1][1] = "GPO MAPPING"
        Else
            ReDim $array2[UBound($array2)+1][2]

            $array2[UBound($array2)-1][0] = $split[2]
            $array2[UBound($array2)-1][1] = "CUSTOM MAPPING"
        EndIf
        ContinueLoop 2
    Next
next

_ArrayDisplay($array2)

does this one work for you? i dont anticipate the mappings will show the right type for you.. i found out that are gpo mappings are mapped by "drive mapping extension" so the status is showed on the custom drive mappings bc they were mapped by the windows kernel

Edited by gcue

Share this post


Link to post
Share on other sites

That code has a lot of errors in it, one is an error with the ContinueLoop and it doesn't run as written. The code below is probably closer to what you're looking for. The 2 mapping types you have may be backwards in the code because I'm not sure how you're figuring out which is which by the information received, so you may have to swap the 2 mapping statements for your array to display correctly.

#include <Constants.au3>
#include <array.au3>

$output = Run(@ComSpec & " /c net use", @SystemDir, @SW_HIDE, $STDOUT_CHILD)

Local $line, $array[1], $array2[1]

While 1
    $line = StdoutRead($output)
    If @error Then ExitLoop

    If $line <> "" And StringInStr($line, "") <> @error Then
        ReDim $array[UBound($array) + 1]
        $array[UBound($array) - 1] = $line
    EndIf
WEnd

For $x = 1 To UBound($array) - 1
    $line = StringStripWS($array[$x], 1 + 4)

    $split = StringSplit($line, Chr(32))

    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $split[2] = ' & $split[2] & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    If StringInStr($split[2], ":") <> @error Then
        ReDim $array2[UBound($array2) + 1][2]

        $array2[UBound($array2) - 1][0] = $split[2]
        $array2[UBound($array2) - 1][1] = "GPO MAPPING"
    Else
        ReDim $array2[UBound($array2) + 1][2]

        $array2[UBound($array2) - 1][0] = $split[2]
        $array2[UBound($array2) - 1][1] = "CUSTOM MAPPING"
    EndIf
Next

_ArrayDisplay($array2)

You'll notice I got rid of the second For...Next loop because it's not needed, you know where the drive letters should be in the $split array, so just look in that element for the information you're looking for. BTW, it's in $split[2] and not $split[1], $split[0] holds the number of array elements returned, not the first part of the split string.


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 Gude
How 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

Share this post


Link to post
Share on other sites

i did swap it out.. thanks!!

looks to be working better =)

many thanks again :)

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
Sign in to follow this  
Followers 0