【.cmd】 バッチファイルスクリプト %15 【.bat】at TECH
【.cmd】 バッチファイルスクリプト %15 【.bat】 - 暇つぶし2ch408:デフォルトの名無しさん
23/07/24 23:51:25.15 wZUfbAlM.net
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}"


次ページ
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch