
Finding NT logon server name
Quote:
> I need to "load balance" sharing of the same data among my domain
controlers
> the way, that users would map the share from the controler they logon to.
It
> seems easy on Windows NT clients (using WScript.ScriptFullName property),
> but on Win9x clients this property returns a drive letter. Does anybody
know
> any other way how to realize this?
> Thanks,
> Zdenek
I am starting to switch our logon scripts to
VBScript here. This is what I
have come up with so far. It works but I don't know if it is the best way
as I am just starting to use VBScript.
option explicit
dim wshShell, wshNetwork, wshEnv
dim regex, server_string, server_name, logon_drive
dim drives, i
set wshShell = CreateObject ("WScript.Shell")
set wshNetwork = CreateObject ("WScript.Network")
set wshEnv = wshShell.Environment("PROCESS")
set regex = New RegExp
' Get the name of the running script
' On 9x it will be Z:\logon.vbs but on NT it will be
\\server\netlogon\logon.vbs
' We check to see if it starts with a letter: and if so we determine the
sever share
' THat the drive is mapped to
server_string = WScript.ScriptFullName
regex.pattern = "^([A-Z]:).*"
regex.IgnoreCase = TRUE
if regex.Test(server_string) then 'Will the regex match?
' Yes, get the logon drive mapping
logon_drive = regex.Replace(server_string,"$1")
set drives = wshNetwork.EnumNetworkDrives
' loop through the mapped drives until we find the correct one
for i = 0 to drives.count - 1 step 2
if drives(i) = logon_drive then
' set the server string to be the network path for the logon
drive
server_string = drives(i+1)
end if
next
end if
' we want to find the server name out of \\server\netlogon.....
regex.pattern = "^\\\\(\w+)\\.*"
server_name = regex.Replace(server_string,"$1")
' server_name is now set to the logon server for the duration of the script.