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

如何使用VBS读取REG_DWORD注册表值并在BGinfo中展示?故障脚本问题排查

Let's break down the issues in your VBS script step by step, and fix it so it works reliably with BGinfo:

Issues in Your Original Script

1. Incorrect Registry Path Format

  • You included HKEY_USERS\\ in your strKeyPath, but since you're already using the HKEY_USERS constant (&H80000003), the path should start directly from the SID.
  • The SID S-1-5 20 has a typo — it should be S-1-5-20 (missing the hyphen between 5 and 20, which is the correct SID for the Local Service account).
  • Corrected path: "S-1-5-20\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DeliveryOptimization\\Settings"

2. Variable Name Typo

You assigned the retrieved registry value to dwValue, but later tried to reference swValue (a misspelling). Since swValue is undefined, it evaluates to an empty string — that's why your message box only showed "t".

3. Unnecessary Variable Confusion

You first set DW="tct", then later overwrite the same variable (VBScript is case-insensitive) with "t "& swValue. This redundant assignment serves no purpose and creates confusion.

Fixed VBS Script

Here's a cleaned-up, error-handling version that properly retrieves the DownloadMode value:

Const HKEY_USERS = &H80000003 
strComputer = "." 
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\\root\\default:StdRegProv") 
strKeyPath = "S-1-5-20\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DeliveryOptimization\\Settings" 
strValueName = "DownloadMode" 

Dim dwValue
' Check if the value was retrieved successfully
If oReg.GetDWORDValue(HKEY_USERS, strKeyPath, strValueName, dwValue) = 0 Then
    ' Output the value directly (BGinfo reads this output)
    WScript.Echo dwValue
Else
    ' Handle cases where the key/value doesn't exist
    WScript.Echo "N/A"
End If
Integrating with BGinfo

To pull this value into your BGinfo display:

  1. Save the corrected script as Get-DeliveryOptimizationMode.vbs in a secure, accessible location (e.g., C:\Scripts\).
  2. Open BGinfo, click Custom > New.
  3. In the custom field dialog:
    • Set Identifier to something descriptive like Delivery Optimization Mode.
    • Set Value to WScript.exe //nologo "C:\Scripts\Get-DeliveryOptimizationMode.vbs" (replace the path with where you saved your script).
    • Click OK, then add this new field to your BGinfo template.

This will automatically display the DownloadMode value (0, 1, or "N/A" if the setting is missing) in your BGinfo output.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 16:12:29