Jump to content

getting server name from mapped drive


Cybertek
 Share

Recommended Posts

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

Link to comment
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

?

Link to comment
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

Link to comment
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

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...