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

能否用VBScript检测设备管理器中Realtek USB FE Family Controller并自动修复?

Answer

Absolutely, you can use VBScript to handle this scenario—detecting your Realtek USB FE Family Controller and automatically running the installer if it’s missing after waking from sleep. Here’s a complete, tailored solution:

1. VBScript to Detect the Device & Trigger Installer

This script uses Windows Management Instrumentation (WMI) to scan for your specific controller and launches the installer if it can’t be found. It’s straightforward and easy to adapt:

Option Explicit

Dim objWMIService, colDevices
Dim strTargetDevice, strInstallerPath
Dim objShell

' Exact name of the device as shown in Device Manager
strTargetDevice = "Realtek USB FE Family Controller"
' Path to your installer (use full absolute path if it's not in the same folder as the script)
strInstallerPath = "TK_NIC_DRIVER_INSTALLER.sfx.exe"

' Connect to the local WMI service
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")

' Query all Plug-and-Play devices matching our target name
' The Replace call escapes single quotes to avoid WQL syntax errors
Set colDevices = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_PnPEntity WHERE Name = '" & Replace(strTargetDevice, "'", "''") & "'", _
    "WQL", _
    48) ' Flags for efficient query execution

' Check if any matching devices were found
If colDevices.Count = 0 Then
    WScript.Echo "Realtek controller not detected. Running driver installer..."
    ' Create a shell object to execute the installer
    Set objShell = CreateObject("WScript.Shell")
    ' Run the installer (1 = show window, True = wait for it to finish before exiting)
    ' Add a silent flag like /s or /quiet if your installer supports it (e.g., strInstallerPath & " /s")
    objShell.Run strInstallerPath, 1, True
Else
    WScript.Echo "Realtek USB FE Family Controller is present and recognized."
End If

' Clean up objects to free memory
Set colDevices = Nothing
Set objWMIService = Nothing
Set objShell = Nothing

Critical Notes for the Script:

  • Exact Device Name: Double-check that strTargetDevice matches the name in Device Manager (right-click the device > Properties > General tab) — even small typos will break the detection.
  • Admin Rights: Installing drivers requires administrative privileges. Run the script as an admin, or configure it to elevate automatically (see the task scheduler section below).
  • Installer Path: If the installer isn’t in the same folder as the script, use the full path (e.g., "C:\Drivers\TK_NIC_DRIVER_INSTALLER.sfx.exe").
  • Silent Installation: Most driver installers support a quiet mode. Check your installer’s documentation for flags like /s or /quiet, and add them to the objShell.Run line if needed.

2. Automate the Script to Run on Wake from Sleep

To make this script run automatically when your computer wakes up, use Windows Task Scheduler:

  • Open Task Scheduler > Click Create Task (not Basic Task, for more control).
  • General Tab: Name the task, check "Run with highest privileges" (required for driver installs).
  • Triggers Tab: Click New > Select "On an event" > Set Log to System, Source to Power-Troubleshooter, Event ID to 1 — this triggers when the system wakes from sleep.
  • Actions Tab: Click New > Action: Start a program > Program/script: wscript.exe > Add arguments: "C:\Full\Path\To\Your\Script.vbs" (use the full path to your saved VBScript file).
  • Settings Tab: Check "Run task as soon as possible after a scheduled start is missed" to cover any missed triggers.

Troubleshooting Tips

  • If the script fails to detect the device when it’s present: Try using Win32_NetworkAdapter instead of Win32_PnPEntity in the WQL query (some network devices show up better here).
  • If the installer won’t run: Verify the path is correct, and test running the installer manually first to confirm it works.
  • WMI Access Issues: If you get WMI-related errors, run winmgmt /verifyrepository in an admin command prompt to repair the WMI repository.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:28:35