一键解决方案在设备管理器中禁用/启用设备(无需第三方工具)?

一键解决方案在设备管理器中禁用/启用设备(无需第三方工具)?

一键解决方案在设备管理器中禁用/启用设备(无需第三方工具)?windows-10scriptdevice-manager4为了解决Windows 10中的一个恼人错误,我找到了一个解决方案。问题是,这需要很多点击操作,如果可能的话,我希望能够自动化这些步骤(脚本?)。以下是Reddit上的上下文链接:

不过,有一个更简单的修复方法,不需要重新启动电脑。你可以进入设备管理器,然后在声音、视频和游戏控制器下找到:Intel Display Audio,将其禁用,然后再启用,这样应该可以解决问题。

有一个答案链接显示如何使用第三方工具(devcon)在命令行执行此操作。但我不想安装/维护它,也不确定它是否适用于Windows 10。我希望能够在没有任何第三方工具的情况下完成这个操作。

不一定要是一个命令行脚本。我只想能够用一个手势完成这个操作(双击桌面图标也可以,或者用Cortana命令也可以)。

- Fuhrmanator4我没有找到在没有Devcon或PowerShell模块下载的情况下解决问题的方法。这里有一篇文章,解释了如何使用PowerShell禁用设备,并使用一个简单的模块进行导入: https://blog.kulman.sk/enabling-and-disabling-hardware-devices-with-powershell/ - Ob1lan2嘿,在Windows 10上,我找到了一些可能会让你感兴趣的东西:Get-PnpDevice。尝试使用这个命令获取您音频设备的友好名称,然后尝试类似这样的操作:Get-PnpDevice -FriendlyName "我的USB音频设备" | Disable-PnpDevice -confirm:$false - Ob1lan1@Ob1lan 在我的系统上运行正常,使用Get-PnpDevice -FriendlyName "Intel(R) Display Audio" | Disable-PnpDevice -confirm:$false; Get-PnpDevice -FriendlyName "Intel(R) Display Audio" | Enable-PnpDevice -confirm:$false -- 我将这段代码放在一个.ps1文件中,然后按照http://stackoverflow.com/a/10137272/1168342的方法创建了一个快捷方式 - 我还没有完全弄清楚如何始终以管理员身份运行它,但右键单击快捷方式可以选择该选项。虽然不是一次性操作,但可能是可行的。谢谢! - Fuhrmanator发布了以管理员身份运行的解决方案答案。希望能对你有所帮助! - Ob1lan3个回答4根据我的研究和您的评论显示命令对您有效,这是可能作为“一次性操作”的最终脚本。我在开头添加了一些指示,可以自动以管理员身份运行(自动提升权限)。当然,这仅在用户是计算机管理员时才有效。

最终脚本可保存为“.ps1”文件,并使用PowerShell执行。

# Get the ID and security principal of the current user account

$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()

$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)

# Get the security principal for the Administrator role

$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator

# Check to see if we are currently running "as Administrator"

if ($myWindowsPrincipal.IsInRole($adminRole))

{

# We are running "as Administrator" - so change the title and background color to indicate this

$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"

$Host.UI.RawUI.BackgroundColor = "DarkBlue"

clear-host

}

else

{

# We are not running "as Administrator" - so relaunch as administrator

# Create a new process object that starts PowerShell

$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";

# Specify the current script path and name as a parameter

$newProcess.Arguments = $myInvocation.MyCommand.Definition;

# Indicate that the process should be elevated

$newProcess.Verb = "runas";

# Start the new process

[System.Diagnostics.Process]::Start($newProcess);

# Exit from the current, unelevated, process

exit

}

Get-PnpDevice -FriendlyName "Intel(R) Display Audio" | Disable-PnpDevice -confirm:$false

Get-PnpDevice -FriendlyName "Intel(R) Display Audio" | Enable-PnpDevice -confirm:$false

- Ob1lan21这个方法可以工作,但是我不确定所有的if/else代码是用来做什么的。当我尝试使用这个方法时,我仍然会弹出一个提升权限的提示(所以实际上有两个操作,就像我刚刚添加的答案那样)。在Windows 10中,我可以在快捷方式的高级选项中勾选“以管理员身份运行”,从而实现与那些代码相同的效果(我认为)。我是不是在你的解决方案中漏掉了什么?奇怪的是,如果我通过设备管理器点击这些操作,就不需要提升权限。 - Fuhrmanator我也很困惑,为什么似乎无法在没有提升权限的情况下执行那些非常简单的 PowerShell 命令... - Christoph回答链接3这个简单的解决方案对我有效。

创建一个Windows快捷方式,目标为:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "Get-PnpDevice -FriendlyName \"Intel(R) Display Audio\" | Disable-PnpDevice -confirm:$false; Get-PnpDevice -FriendlyName \"Intel(R) Display Audio\" | Enable-PnpDevice -confirm:$false"

在快捷方式属性 > 快捷方式 > 高级属性中,勾选"以管理员身份运行"

最终需要两个手势,因为你需要允许权限提升。当我尝试@Ob1lan的回答时,我还必须点击允许提升(第二个手势)。所以,根据原始问题来说,这不是一个理想的答案。注意:手动禁用/启用设备(如问题描述中所述)不需要权限提升。

我避免使用脚本文件(.ps1)的原因是因为它需要额外的解决方案来处理安全问题,即使有很多管理员检查,也不如勾选“以管理员身份运行”选项方便。更多信息请参考https://stackoverflow.com/questions/4037939/powershell-says-execution-of-scripts-is-disabled-on-this-system。

- Fuhrmanator1好的解决方案,是否可以使用一个语句来切换设备的开/关状态,还是我必须使用两个快捷方式? - Albin回答链接0我在使用@Ob1lan的脚本时遇到了一些问题,因为为了使其正常工作(即允许脚本提升权限),Powershell Execution Policy必须允许。一种方法是全局设置使用Set-ExecutionPolicy。不过,我更倾向于保持全局策略不变,并在需要时绕过它,使用-ExecutionPolicy ByPass参数。

下面是稍作修改后的脚本,我现在正在使用它来禁用触摸屏。除了添加绕过参数外,我还添加了-WindowStyle hidden参数,以防止太多窗口弹出干扰我的屏幕。(提示:如果脚本不能按预期工作,建议您首先将该参数替换为-noexit参数,以查看任何错误消息。)

# Get the ID and security principal of the current user account

$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()

$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)

# Get the security principal for the Administrator role

$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator

# Check to see if we are currently running "as Administrator"

if ($myWindowsPrincipal.IsInRole($adminRole))

{

# We are running "as Administrator" - so change the title and background color to indicate this

$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + " (Elevated)"

$Host.UI.RawUI.BackgroundColor = "DarkBlue"

clear-host

}

else

{

# We are not running "as Administrator" - so relaunch as administrator

# Create a new process object that starts PowerShell

$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";

# Specify the current script path and name as a parameter, hide window and bypass execution policy (in case it has not been disabled globally)

$newProcess.Arguments = '-ExecutionPolicy ByPass -WindowStyle hidden ' + $myInvocation.MyCommand.Definition + '" ';

# Here are the changes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

# Indicate that the process should be elevated

$newProcess.Verb = "runas";

# Start the new process

[System.Diagnostics.Process]::Start($newProcess);

# Exit from the current, unelevated, process

exit

}

Get-PnpDevice | Where-Object {$_.FriendlyName -like '*touch screen*'} | Enable-PnpDevice -Confirm:$false

- Christoph回答链接

相关推荐

​闪婚什么意思(闪婚的人都是怎么想的)
beat365唯一网址

​闪婚什么意思(闪婚的人都是怎么想的)

⌛ 09-29 👁️ 675
绦虫在人体能存活多久
365软件下载

绦虫在人体能存活多久

⌛ 11-21 👁️ 8163