You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在BGInfo中将Logon Server与Logon Domain合并为同一字段

在BGInfo中合并Logon Server与Logon Domain字段(点分隔格式)

需求:在BGInfo中将Logon Server和Logon Domain字段合并为同一行,格式为「Logon Server.Logon Domain」。

现有脚本仅能获取用户域与计算机名合并,无法获取Logon Server:

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

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

尝试过将字段改为obj.network.UserServer但无效,也知道CMD中可通过echo %logonserver%获取Logon Server,但不清楚如何整合到VBS脚本中。


解决方案

通过读取注册表对应的键值来获取Logon Server和Logon Domain,再合并输出:

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 strLogonServer
dim strLogonDomain

Set objShell = CreateObject("WScript.Shell")

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

' 移除Logon Server默认带的双反斜杠前缀
strLogonServer = Replace(strLogonServer, "\\", "")

WScript.Echo strLogonServer & "." & strLogonDomain

说明:

  • ReadFromRegistry函数用于安全读取注册表键值,读取失败时返回指定默认值
  • 从HKEY_CURRENT_USER\Volatile Environment路径下读取LOGONSERVER和USERDOMAIN两个系统维护的键值
  • 额外处理Logon Server的双反斜杠前缀,避免输出格式出现多余符号

内容的提问来源于stack exchange,提问作者Nik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 09:35:23