質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

VBScript

VBScript(Visual Basic Scripting Edition)はMicrosftが開発したスクリプト言語であり、Visual Basicのサブセットです。

Q&A

0回答

1616閲覧

VBScriptでIEのアドオン管理の有効・無効を切替

kmykmy

総合スコア2

Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

VBScript

VBScript(Visual Basic Scripting Edition)はMicrosftが開発したスクリプト言語であり、Visual Basicのサブセットです。

0グッド

0クリップ

投稿2020/06/15 02:40

編集2020/06/15 02:52

前提・実現したいこと

OS:Windows10 64bit IE Ver:11 32bit IE11でアドオンの管理に登録されているActiveXの 有効→無効→有効の切替をVBSで行いたい。 有効→無効,無効→有効を別のVBSに分けて各々叩くと切替はできるが 1つのVBSに結合すると以下のエラーメッセージが発生しました。

発生している問題・エラーメッセージ

エラー:名前が二重に定義されています。 コード:800A0411 ソース:Mcirosoft VBScript コンパイルエラー

該当のソースコード

VBScript

1 2On Error Resume Next 3 4'Global constants and variables 5Const HKEY_CURRENT_USER = &H80000001 6strComputer = "." ' Can be changed to name of remote computer. 7g_strKeyPathA = "Software\Microsoft\Windows" & _ 8 "\CurrentVersion\Ext\Settings\{CA8A9780-280D-11CF-A24D-444553540000}" 9g_strKeyPathB = "Software\Microsoft\Windows" & _ 10 "\CurrentVersion\Ext\Stats\{CA8A9780-280D-11CF-A24D-444553540000}\iexplore" 11 12'Connect with WMI service and StdRegProv class. 13Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & _ 14 strComputer & "\root\default:StdRegProv") 15If Err = 0 Then 16 blnCreateSubKeys = CreateSubKeys 17 If blnCreateSubKeys Then 18 SetValues 19 End If 20Else 21' WScript.Echo "Unable to connect to WMI service on " & strComputer & "." 22' WScript.Echo Err.Number 23' WScript.Echo Err.Source 24' WScript.Echo Err.Description 25End If 26Err.Clear 27 28'****************************************************************************** 29 30Function CreateSubKeys 31 32intReturnA = objReg.CreateKey(HKEY_CURRENT_USER, g_strKeyPathA) 33If intReturnA <> 0 Then 34' WScript.Echo "ERROR: Unable to create registry path:" & VbCrLf & _ 35' "HKEY_CURRENT_USER\" & strKeyPathA 36End If 37intReturnB = objReg.CreateKey(HKEY_CURRENT_USER, g_strKeyPathB) 38If intReturnB <> 0 Then 39' WScript.Echo VbCrLf & "ERROR: Unable to create registry path:" & VbCrLf & _ 40 "HKEY_CURRENT_USER\" & strKeyPathB 41End If 42If (intReturnA = 0) And (intReturnB = 0) Then 43' WScript.Echo VbCrLf & "Created registry subkeys:" & VbCrLf & _ 44 "HKEY_CURRENT_USER\" & g_strKeyPathA & VbCrLf & "HKEY_CURRENT_USER\" & _ 45 g_strKeyPathB 46 CreateSubKeys = True 47Else 48' WScript.Echo "Unable to create registry subkeys." 49 CreateSubKeys = False 50End If 51 52End Function 53 54'****************************************************************************** 55 56Sub SetValues 57 58'Local variables 59strEntryNameA1 = "Flags" 60strEntryNameA2 = "Version" 61intValueA1 = 1 62strValueA2 = "*" 63strEntryNameB1 = "Blocked" 64strEntryNameB2 = "Count" 65strEntryNameB3 = "Type" 66strEntryNameB4 = "Time" 67intValueB1 = 4 68intValueB2 = &Hdf 69intValueB3 = 3 70arrValueB4 = Array(&Hd4, &H07, &H07, &H00, &H04, &H00, &H1d, &H00, &H0c, _ 71 &H00, &H20, &H00, &H2b, &H00, &H80, &H00) 72 73intReturnA1 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathA, _ 74 strEntryNameA1, intValueA1) 75intReturnA2 = objReg.SetStringValue(HKEY_CURRENT_USER, g_strKeyPathA, _ 76 strEntryNameA2, strValueA2) 77If (intReturnA1 = 0) And (intReturnA2 = 0) Then 78' WScript.Echo VbCrLf & "Added registry entries to:" & VbCrLf & _ 79 "HKEY_CURRENT_USER\" & g_strKeyPathA & VbCrLf & _ 80 "Entry: " & strEntryNameA1 & VbTab & "Value: " & intValueA1 & VbCrLf & _ 81 "Entry: " & strEntryNameA2 & VbTab & "Value: " & strValueA2 82Else 83' WScript.Echo VbCrLf & "ERROR: Unable to add registry entries to:" & _ 84 VbCrLf & "HKEY_CURRENT_USER\" & g_strKeyPathA & "." 85End If 86 87intReturnB1 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathB, _ 88 strEntryNameB1, intValueB1) 89intReturnB2 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathB, _ 90 strEntryNameB2, intValueB2) 91intReturnB3 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathB, _ 92 strEntryNameB3, intValueB3) 93intReturnB4 = objReg.SetBinaryValue(HKEY_CURRENT_USER, g_strKeyPathB, _ 94 strEntryNameB4, arrValueB4) 95If (intReturnB1 = 0) And (intReturnB2 = 0) And (intReturnB3 = 0) _ 96 And (intReturnB4 = 0) Then 97 For Each Value in arrValueB4 98 strValueB4 = strValueB4 & Hex(Value) & " " 99 Next 100' WScript.Echo VbCrLf & "Added registry entries to:" & VbCrLf & _ 101 "HKEY_CURRENT_USER\" & g_strKeyPathA & VbCrLf & _ 102 "Entry: " & strEntryNameB1 & VbTab & "Value: " & Hex(intValueB1) & _ 103 VbCrLf & "Entry: " & strEntryNameB2 & VbTab & "Value: " & _ 104 Hex(intValueB2) & VbCrLf & "Entry: " & strEntryNameB3 & VbTab & _ 105 "Value: " & Hex(intValueB3) & VbCrLf & "Entry: " & strEntryNameB4 & _ 106 VbTab & "Value: " & strValueB4 107Else 108' WScript.Echo VbCrLf & "ERROR: Unable to add registry entries to:" & _ 109 VbCrLf & "HKEY_CURRENT_USER\" & g_strKeyPathB & "." 110End If 111 112End Sub 113 114On Error Resume Next 115 116'Global constants and variables 117Const HKEY_CURRENT_USER = &H80000001 118strComputer = "." ' Can be changed to name of remote computer. 119g_strKeyPathA = "Software\Microsoft\Windows" & _ 120 "\CurrentVersion\Ext\Settings\{CA8A9780-280D-11CF-A24D-444553540000}" 121g_strKeyPathB = "Software\Microsoft\Windows" & _ 122 "\CurrentVersion\Ext\Stats\{CA8A9780-280D-11CF-A24D-444553540000}\iexplore" 123 124'Connect with WMI service and StdRegProv class. 125Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & _ 126 strComputer & "\root\default:StdRegProv") 127If Err = 0 Then 128 blnCreateSubKeys = CreateSubKeys 129 If blnCreateSubKeys Then 130 SetValues 131 End If 132Else 133' WScript.Echo "Unable to connect to WMI service on " & strComputer & "." 134' WScript.Echo Err.Number 135' WScript.Echo Err.Source 136' WScript.Echo Err.Description 137End If 138Err.Clear 139 140'****************************************************************************** 141 142Function CreateSubKeys 143 144intReturnA = objReg.CreateKey(HKEY_CURRENT_USER, g_strKeyPathA) 145If intReturnA <> 0 Then 146' WScript.Echo "ERROR: Unable to create registry path:" & VbCrLf & _ 147 "HKEY_CURRENT_USER\" & strKeyPathA 148End If 149intReturnB = objReg.CreateKey(HKEY_CURRENT_USER, g_strKeyPathB) 150If intReturnB <> 0 Then 151' WScript.Echo VbCrLf & "ERROR: Unable to create registry path:" & VbCrLf & _ 152 "HKEY_CURRENT_USER\" & strKeyPathB 153End If 154If (intReturnA = 0) And (intReturnB = 0) Then 155' WScript.Echo VbCrLf & "Created registry subkeys:" & VbCrLf & _ 156 "HKEY_CURRENT_USER\" & g_strKeyPathA & VbCrLf & "HKEY_CURRENT_USER\" & _ 157 g_strKeyPathB 158 CreateSubKeys = True 159Else 160' WScript.Echo "Unable to create registry subkeys." 161 CreateSubKeys = False 162End If 163 164End Function 165 166'****************************************************************************** 167 168Sub SetValues 169 170'Local variables 171strEntryNameA1 = "Flags" 172strEntryNameA2 = "Version" 173intValueA1 = 0 174strValueA2 = "*" 175strEntryNameB1 = "Blocked" 176strEntryNameB2 = "Count" 177strEntryNameB3 = "Type" 178strEntryNameB4 = "Time" 179intValueB1 = 4 180intValueB2 = &Hdf 181intValueB3 = 3 182arrValueB4 = Array(&Hd4, &H07, &H07, &H00, &H04, &H00, &H1d, &H00, &H0c, _ 183 &H00, &H20, &H00, &H2b, &H00, &H80, &H00) 184 185intReturnA1 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathA, _ 186 strEntryNameA1, intValueA1) 187intReturnA2 = objReg.SetStringValue(HKEY_CURRENT_USER, g_strKeyPathA, _ 188 strEntryNameA2, strValueA2) 189If (intReturnA1 = 0) And (intReturnA2 = 0) Then 190' WScript.Echo VbCrLf & "Added registry entries to:" & VbCrLf & _ 191 "HKEY_CURRENT_USER\" & g_strKeyPathA & VbCrLf & _ 192 "Entry: " & strEntryNameA1 & VbTab & "Value: " & intValueA1 & VbCrLf & _ 193 "Entry: " & strEntryNameA2 & VbTab & "Value: " & strValueA2 194Else 195' WScript.Echo VbCrLf & "ERROR: Unable to add registry entries to:" & _ 196 VbCrLf & "HKEY_CURRENT_USER\" & g_strKeyPathA & "." 197End If 198 199intReturnB1 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathB, _ 200 strEntryNameB1, intValueB1) 201intReturnB2 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathB, _ 202 strEntryNameB2, intValueB2) 203intReturnB3 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathB, _ 204 strEntryNameB3, intValueB3) 205intReturnB4 = objReg.SetBinaryValue(HKEY_CURRENT_USER, g_strKeyPathB, _ 206 strEntryNameB4, arrValueB4) 207If (intReturnB1 = 0) And (intReturnB2 = 0) And (intReturnB3 = 0) _ 208 And (intReturnB4 = 0) Then 209 For Each Value in arrValueB4 210 strValueB4 = strValueB4 & Hex(Value) & " " 211 Next 212' WScript.Echo VbCrLf & "Added registry entries to:" & VbCrLf & _ 213 "HKEY_CURRENT_USER\" & g_strKeyPathA & VbCrLf & _ 214 "Entry: " & strEntryNameB1 & VbTab & "Value: " & Hex(intValueB1) & _ 215 VbCrLf & "Entry: " & strEntryNameB2 & VbTab & "Value: " & _ 216 Hex(intValueB2) & VbCrLf & "Entry: " & strEntryNameB3 & VbTab & _ 217 "Value: " & Hex(intValueB3) & VbCrLf & "Entry: " & strEntryNameB4 & _ 218 VbTab & "Value: " & strValueB4 219Else 220' WScript.Echo VbCrLf & "ERROR: Unable to add registry entries to:" & _ 221 VbCrLf & "HKEY_CURRENT_USER\" & g_strKeyPathB & "." 222End If 223 224End Sub

試したこと

・該当箇所のConst HKEY_CURRENT_USER = &H80000001 の値変更
・有効→無効,無効→有効を別のVBSに分けて実行

補足情報(FW/ツールのバージョンなど)

サクラエディタで作業しております。
【2020/06/15追記】
プログラミングの知識はあまり無く
MS関連のページから拾ったものに対しClassIDを変更して動作確認をしております。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問