【.cmd】 バッチファイルスクリプト %15 【.bat】 (773レス)
上下前次1-新
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん
413: デフォルトの名無しさん [sage] 2023/07/26(水) 01:41:27.08 ID:HHyO4+3x(1) AAS
>>406406(1): デフォルトの名無しさん [sage] 2023/07/23(日) 21:05:51.47 ID:JLqJNtpp(1) AAS
set id="~"
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "delims=" %%i IN ('devcon status !id!') DO (
set a=%%i
if "!a!" NEQ "!a:Driver is running=!" devcon disable !id! & goto :eof
if "!a!" NEQ "!a:Device is disabled=!" devcon enable !id! & goto :eof
)
管理者権限で実行
複数の matching の場合はどうなるか知らない
>>409409(1): デフォルトの名無しさん [sage] 2023/07/24(月) 23:51:25.15 ID:wZUfbAlM(1/2) AAS
WMI(CIM)が楽かな。
powershellでもVBScriptでもwmicでもお好きなもので。
PowerShell版:
$enabledCd = 0
$disabledCd = 22
$methodName = $null
$device = Get-CimInstance -Query 'select * from Win32_PnpEntity where Name = "Fax"'
if ($device.Status -eq 'OK' -and $device.ConfigManagerErrorCode -eq $enabledCd) {
$methodName = 'Disable'
}
elseif ($device.Status -eq 'Error' -and $device.ConfigManagerErrorCode -eq $disabledCd) {
$methodName = 'Enable'
}
if (! [string]::IsNullOrEmpty($methodName)) {
$result = Invoke-CimMethod -InputObject $device -MethodName $methodName
$result
}
ワンライナー版:
powershell -c "$d=gcim -cl Win32_PnpEntity -f 'Name=''Fax'''; $s,$c=$d.Status,$d.ConfigManagerErrorCode; if($n=if($s -eq 'OK' -and $c -eq 0){'Disable'}elseif($s -eq 'Error' -and $c -eq 22){'Enable'}){$d|icim -m $n}"
ありがとうございます
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.036s