VBSでPINGコマンドを実行する
バックアップをVBSで実行しているのですが、
2つの作業環境がある場合に、違う環境で実行すると残念な結果になります。
そこで実装の中にPINGコマンドを実行して
ネットワークがどちらにあるか事前にチェックする事にしました。
Dim objWMIService ' Windows Managements Dim PingSet ' Win32_PingStatusクラス Dim Ping ' 対象Ping Set objWMIService = GetObject("winmgmts:\\.") Set PingSet = objWMIService.ExecQuery _ ("Select * From Win32_PingStatus Where Address = 'IPアドレス'") For Each Ping In PingSet Select Case Ping.StatusCode Case 0 checkPing = True Case 11010 checkPing = False End Select Next If checkPing = True Then MsgBox "OK" Else MsgBox "NG" End If
これで環境を間違って実行した場合でも処理が走りません(ー。ー)