0

I am trying to combine the Logon Server and Logon Domain fields on BGInfo so they are on the same line and have a dote to separate them, so Logon Server.Logon Domain. The script I have retrieves the Logon Domain and combines the computer name but I can't find anything to retrieve the Logon Server.

 Set objNetwork = CreateObject("WScript.Network")
 strLogonServer = objNetwork.UserDomain
 strLogonDomain = objNetwork.ComputerName

 Set objShell = CreateObject("WScript.Shell")
 objShell.Popup strLogonServer & "." & strLogonDomain

Ive tried changing the Logon Domain string to obj.network.UserServer but that doesn't change it.

I also know that CMD produces the logon server via Echo %logonserver% but not sure how to implement that into the string

EDIT:

Created a solution,

Function ReadFromRegistry(strRegistryKey, strDefault) Dim WSHShell, value

On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
value = WSHShell.RegRead( strRegistryKey )

If err.number <> 0 Then
    readFromRegistry = strDefault
Else
    readFromRegistry = value
End If

Set WSHShell = Nothing

End Function

dim objShell dim strLoginServer dim strLoginUser

Set objShell = CreateObject("WScript.Shell")

strLogonServer = ReadFromRegistry("HKEY_CURRENT_USER\Volatile Environment\LOGONSERVER", "error") strLoginUser = ReadFromRegistry("HKEY_CURRENT_USER\Volatile Environment\USERDOMAIN", "error")

strLogonServer = replace(strLogonServer, "", "")

Echo strLogonServer & "." & strLoginUser

Outputs the LogonServer and LogonDomain from registry as an echo with a dot in the middle.

Nik
  • 3
  • 2
  • 1
    Use [ExpandEnvironmentStrings](https://www.vbsedit.com/html/c1c1f29c-2a30-46a1-bae7-c17f8af55a19.asp) to get the `logonserver` environment variable in VBScript. – LesFerch Dec 16 '22 at 17:03
  • I have tried to combine the code you suggested in that link but nothing seems to work.Set objNetwork = CreateObject("WScript.Network") strLogonServer = objNetwork.UserDomain Set WshShell = CreateObject("WScript.Shell") Set objShell = CreateObject("WScript.Shell") Echo WshShell.ExpandEnvironmentStrings("%WinDir%") & "." & strLogonDomain – Nik Dec 19 '22 at 10:27

0 Answers0