dポイントプレゼントキャンペーン実施中!

Windows7でVBScriptによるネットワークアダプタの有効/無効を取得

こんにちは。
ネットで情報収集しているのですが、どうも答えがわからずにいます。
どなたかアドバイスをお願い致します。

Windows7でVBScriptを使ってネットワークアダプタの有効/無効を取得し、
テキストファイルに保存したいです。
WindowsXPでは正常に動くのですがWindows7だとエラーが返ってきます。

エラーの原因は、
「if strFolderItem.name = "ネットワーク接続" then」
の所で「strFolderItem.name = "ネットワーク接続"」に該当する
ものが一つも無い事が原因のようです。

Xpでは"ネットワーク接続"だったのが7では名称が変わったのか。
それとも、そもそもこのobjApp.Namespace(3)では取得できないのか。
答えがわかりません。
よろしくお願いいたします。

以下、コードです。
'//-----------------------------------------
' ファイル名:test.vbs
' このVBScriptと同じフォルダ内に
' 「NetAdapterCheck.log」という空のファイルを準備した上で実行する。

'変数の宣言を明示的にする
Option Explicit

'変数の宣言
Dim objApp
Dim objCtrPanel
Dim objConnection
Dim objAdapter
Dim strEnable
Dim strDisable
Dim strFolderName
Dim strFolderItem
Dim strVerb
Dim intCnt
Dim objFileSys
Dim objOutFile

set objApp = createobject("shell.application")
set objCtrPanel = objApp.Namespace(3)
strEnable = "有効にする(&A)"
strDisable = "無効にする(&B)"

for each strFolderItem in objCtrPanel.items
if strFolderItem.name = "ネットワーク接続" then
set objConnection = strFolderItem.getfolder: exit for
end if
next

strFolderName = ""
intCnt = 0

for each strFolderItem in objConnection.items
set objAdapter = strFolderItem
for each strVerb in objAdapter.verbs
if strVerb.name = strEnable then
intCnt = intCnt + 1
strFolderName = strFolderName & intCnt & "<>" & "無効<>" & strFolderItem.name & vbCrLf
elseif strVerb.name = strDisable then
intCnt = intCnt + 1
strFolderName = strFolderName & intCnt & "<>" & "有効<>" & strFolderItem.name & vbCrLf
end if
next
next
'ファイルに書き込み
Set objFileSys = WScript.CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFileSys.OpenTextFile("NetAdapterCheck.log",2)'1=読込、2=上書き、3=追記
objOutFile.WriteLine strFolderName
'テキストファイルのクローズ
objOutFile.Close
'オブジェクト破棄
Set objFileSys = Nothing
Set objOutFile = Nothing


'オブジェクトの開放
set objApp = nothing
set objCtrPanel = nothing
set objConnection = nothing
set objAdapter = nothing
'//-----------------------------

A 回答 (1件)

VISTA 以降であればWMIで取得できるようです。


http://technet.microsoft.com/ja-jp/magazine/2006 …

今のまま進めてゆくには、Excel などのVBA に提示されたVBSを移植して
objApp.Namespace(????) や objCtrPanel.items を総なめするとか
適当なところで中断させてローカルウィンドウで調べるとか、出来ませんか?
当方Win7は持ち合わせておりませんので此処まで。
    • good
    • 0
この回答へのお礼

とても助かりました。
ありがとうございました。

お礼日時:2010/10/13 10:08

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!