如何使用批处理或命令行打开/关闭 USB 端口的电源?我正在使用 Windows 8 来执行此操作。有谁知道我能做什么?我有 4 个 USB 端口。
我一直在寻找如何在 PowerShell 中使用命名空间来处理 Windows 10 锁定屏幕并遇到了这个答案:https : //superuser.com/a/1062551/700258,但是它没有说明如何导入或将该命名空间添加到 PowerShell 以供使用。我尝试为程序集查找引用的 DLL 文件,但它们不在我的计算机上。当我看到它们是 Windows 桌面扩展 API 的一部分时,我出去下载了 Windows 10 SDK,但 DLL 文件也不在其中。如何在 PowerShell 脚本中使用 Windows.System.UserProfile 命名空间中的此 LockScreen 类?
我从这里得到了这段代码,它根据收到的参数启动或停止蓝牙服务。
bluetooth.ps1 -BluetoothStatus On
Run Code Online (Sandbox Code Playgroud)
或者
bluetooth.ps1 -BluetoothStatus Off
Run Code Online (Sandbox Code Playgroud)
我想修改它,以便我可以使用简单的 ahk 键绑定在不带参数的情况下调用它:
#b::
Run, C:\Users\user\Desktop\bluetooth.ps1
return
Run Code Online (Sandbox Code Playgroud)
然后,脚本应该“自行”检查蓝牙是否打开或关闭,并执行必要的操作来更改状态:如果打开,则应停止蓝牙;如果打开,则应停止蓝牙。如果关闭它应该启动它。
[CmdletBinding()] Param (
[Parameter(Mandatory=$true)][ValidateSet('Off', 'On')][string]$BluetoothStatus
)
If ((Get-Service bthserv).Status -eq 'Stopped') { Start-Service bthserv }
Add-Type -AssemblyName System.Runtime.WindowsRuntime
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
Function Await($WinRtTask, $ResultType) {
$asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
$netTask = $asTask.Invoke($null, @($WinRtTask))
$netTask.Wait(-1) | Out-Null
$netTask.Result
}
[Windows.Devices.Radios.Radio,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
[Windows.Devices.Radios.RadioAccessStatus,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
Await ([Windows.Devices.Radios.Radio]::RequestAccessAsync()) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null …
Run Code Online (Sandbox Code Playgroud) powershell ×2
windows-10 ×2
batch ×1
bluetooth ×1
power ×1
usb ×1
uwp ×1
windows-8 ×1
windows-8.1 ×1