2
1

More than 5 years have passed since last update.

[VBScript] 管理者権限として実行(レジストリ変更)

Last updated at Posted at 2015-08-19

コードには以下のトピックスが含まれています
* 管理者権限として実行するVBScript (UACの確認ウィンドウが出てきます)
* VBScriptでダイアログを出してユーザーに判断をゆだねる
* VBScriptでレジストリを書き込む
* SeleniumにてIE11を利用する際のレジストリ編集 (https://code.google.com/p/selenium/wiki/InternetExplorerDriver)
* (ほかにもSeleniumのIEdriverを利用する際はズームレベル100%とか拡張保護モード無効にするとかいろいろ事前設定が必要なのに注意)

test.vbs
Option Explicit

Dim WMI, OS, Value, Shell, wssh, fs, sh, ans
Dim path1, path2

do while WScript.Arguments.Count = 0 and WScript.Version >= 5.7
    '##### WScript5.7 または Vista 以上かをチェック
    Set WMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set OS = WMI.ExecQuery("SELECT *FROM Win32_OperatingSystem")
    For Each Value in OS
    if left(Value.Version, 3) < 6.0 then exit do
    Next

    '##### 管理者権限で実行
    Set Shell = CreateObject("Shell.Application")
    Shell.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ uac", "", "runas"

    WScript.Quit
loop

' --------------------- レジストリ登録
ans = Msgbox("レジストリを登録します。よろしいですか?", vbYesNo, "Modify Registry")
If ans = vbYes Then
    ' selenium IE11 32bit
    ' wssh.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE\iexplore.exe", 0, "REG_DWORD"
    ' selenium IE11 64bit
    wssh.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE\iexplore.exe", 0, "REG_DWORD"
    On Error Resume Next
    MsgBox("登録しました。")
End If
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1