gpt4 book ai didi

windows - 如何以编程方式为某些 USB 设备禁用 "Enhanced Power Management"?

转载 作者:可可西里 更新时间:2023-11-01 10:06:08 28 4
gpt4 key购买 nike

我正在开发与自定义 USB 设备交互的软件。该设备将自身呈现为 HID 设备,软件通过文件 I/O 与其交互。

由于 Windows 8.1 的变化,操作系统不断重启设备,这导致软件出现问题。

根据此知识库文章:http://support.microsoft.com/kb/2900614 ,如果 USB 设备出现此问题,Microsoft 建议禁用增强型电源管理功能,并且在手动执行此操作后问题会消失。

现在,我想修改软件的安装程序以禁用我们所有设备的此设置,而不仅仅是特定设备实例。

有没有办法做到这一点?是通过 Windows API 调用,还是通过会影响特定 ProductID/VendorID 组合的所有实例的注册表设置?

例如我想修改以下所有实例:

  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_11AE&PID_07CE

包括在安装程序执行后可能连接到系统的任何 future 实例。

最佳答案

这是我编写的示例脚本,用于禁用所有 Datalogic 品牌 USB 设备(供应商 ID 0x05F9)的电源管理。您可能只需更改 For Each 循环中条件语句中的“VID_05F9&”,使其与您需要修改的键相匹配。请注意,还会处理必要的 UAC 提升。

'Filename: USBPMFIX.VBS
'Author: Matthew Mellon <mmellon@ecrs.com>
'Date: 2014-12-12
'Desc: Disables enhanced power management on all Datalogic USB devices.
'License: This source code is released into the public domain.

'Checks if the script is running elevated (UAC)
function isElevated
Set shell = CreateObject("WScript.Shell")
Set whoami = shell.Exec("whoami /groups")
Set whoamiOutput = whoami.StdOut
strWhoamiOutput = whoamiOutput.ReadAll

If InStr(1, strWhoamiOutput, "S-1-16-12288", vbTextCompare) Then
isElevated = True
Else
isElevated = False
End If
end function

'Re-runs the process prompting for priv elevation on re-run
sub uacPrompt

'Check if we need to run in C or W script
interpreter = "wscript.exe"
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
interpreter = "wscript.exe"
else
interpreter = "cscript.exe"
end if

'Start a new instance with an elevation prompt first
Set shellApp = CreateObject("Shell.Application")
shellApp.ShellExecute interpreter, Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1

'End the non-elevated instance
WScript.Quit
end sub

if not isElevated Then uacPrompt

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Enum\USB"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each Subkey in arrSubKeys
If Left(Subkey,9) = "VID_05F9&" And Left(Right(Subkey,6),5) = "&MI_0" Then
strKeyPath = "SYSTEM\CurrentControlSet\Enum\USB\"+Subkey
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrInnerSubKeys
For Each InnerSubkey in arrInnerSubKeys
strFullKey = "SYSTEM\CurrentControlSet\Enum\USB\"+Subkey+"\"+InnerSubkey+"\Device Parameters"
objReg.SetDWORDValue HKEY_LOCAL_MACHINE, strFullKey, "EnhancedPowerManagementEnabled", 0
Next
End If
Next

关于windows - 如何以编程方式为某些 USB 设备禁用 "Enhanced Power Management"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23122549/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com