LoginSignup
2
0

More than 1 year has passed since last update.

LoLをプレイする時にAutoHotKeyが起動していたらAutoHotKeyを終了させる常駐VBS

Last updated at Posted at 2021-07-19

概要

LoLでランク戦に挑んだら強制退出させられた事がありますか?
私は何度もあります😭
そこでLeagueClient.exeとAutoHotkey.exeが同時に起動していたらAutoHotkey.exeを終了させるVBScriptをコピペで作りました。このスクリプトに適当な名前aaa.vbsを付けてをスタートアップに入れておけばもう悲しい思いをしなくてすみますね😄

VBScript

Option Explicit
'------------------------------------------------------------------------------
'管理者権限でこのスクリプトを実行する
'------------------------------------------------------------------------------
Dim WMI, OS, Value, Shell
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

'-------------------------------------------------------------------------------
' プロセスの取得
'-------------------------------------------------------------------------------
Function getProcesses(processName)
    Dim service
    Set service = CreateObject("WbemScripting.SWbemLocator").ConnectServer
    Set getProcesses = service.ExecQuery("Select * From Win32_Process Where Caption='" & processName & "'")
    Set service = Nothing
End Function

'----------------------------------------------------------
' LeagueClientが起動している時にAutoHotkeyが起動していたら終了させる
'----------------------------------------------------------
Dim processesAutoHotkey, processesLeagueClient, process
Do While 1
    Set processesAutoHotkey = getProcesses("AutoHotkey.exe")
    Set processesLeagueClient = getProcesses("LeagueClient.exe")
    if 0 < processesAutoHotkey.Count and 0 < processesLeagueClient.Count then
        For Each process in processesAutoHotkey
          process.Terminate
        Next
        MsgBox("AutoHotkey.exeを停止しました")
    end if
    WScript.Sleep 10000
Loop
2
0
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
0