Sign in to follow this  
Followers 0
Cybertek

getting server name from mapped drive

7 posts in this topic

Is there a way to get the name of a server that is mapped. The drive letter is always the same but the length of the server name is nerver the same.

Here is what I got to work if the server name is a set length.....there has to be an easier way.

$var = RegRead("HKEY_CURRENT_USER\Network\P", "RemotePath")

MsgBox(0,"done", $var)

$var2 = stringmid($var, 3, 10)

MsgBox(0,"Server", $var2)

thanks,

cybertek

Share this post


Link to post
Share on other sites



Have you looked in the registry?

come on man look at the code i posted

$var = RegRead("HKEY_CURRENT_USER\Network\P", "RemotePath")

from \\servername001\personaldata\folder

I need to get the part servername001 with out the backslashes

Share this post


Link to post
Share on other sites

#include <Array.au3>
#include <String.au3>
Dim $sServer = '\\servername001\personaldata\folder'
Dim $Match = _StringBetween($sServer, '\\\\', '\\', -1, 1)
If IsArray($Match) Then _ArrayDisplay($Match)

$Match = StringRegExp($sServer, '(?<=\\\\)([^\\]*)', 1)
If IsArray($Match) Then _ArrayDisplay($Match)

Dim $iStart = StringInStr($sServer, '\\') + 2
Dim $iEnd = StringInStr($sServer, '\', 0, 1, $iStart)

If $iStart And $iEnd Then
    $Match = StringMid($sServer, $iStart, $iEnd-$iStart)
    MsgBox(0x10, 'Title', 'Match: ' & $Match)
EndIf

Exit

?

Share this post


Link to post
Share on other sites

#include <Array.au3>
#include <String.au3>
Dim $sServer = '\\servername001\personaldata\folder'
Dim $Match = _StringBetween($sServer, '\\\\', '\\', -1, 1)
If IsArray($Match) Then _ArrayDisplay($Match)

$Match = StringRegExp($sServer, '(?<=\\\\)([^\\]*)', 1)
If IsArray($Match) Then _ArrayDisplay($Match)

Dim $iStart = StringInStr($sServer, '\\') + 2
Dim $iEnd = StringInStr($sServer, '\', 0, 1, $iStart)

If $iStart And $iEnd Then
    $Match = StringMid($sServer, $iStart, $iEnd-$iStart)
    MsgBox(0x10, 'Title', 'Match: ' & $Match)
EndIf

Exit

?

Well I don't entirely understand it but this is essentially what I was looking for

Dim $Match = _StringBetween($sServer, '\\\\', '\\', -1, 1)

$Match = StringRegExp($sServer, '(?<=\\\\)([^\\]*)', 1)

these are the two lines that confuse me(more along the lines the the argument for the pattern)

any chance you could maybe explain it a little to me

thanks so much for the help,

Cybertek

Share this post


Link to post
Share on other sites

Hi Mate,

First things first, have you even looked at the helpfile for those functions?

Once you've done that you should understand whats happening a little better...

Cheers,

Brett

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