電卓ボタンから電卓の複数起動を回避する試行錯誤

マイクロソフトのエルゴノミック系のキーボードを使っている。
テンキーに電卓ボタンがついていて便利なのだが、押すたびに電卓が立ち上がる。
複数起動を避けるために試行錯誤したメモ。

system32/calc.exeがランチャーの様子。
これをいじりたかったけど、権限がうんたらでうまくいかず。

batかvbsで、電卓を立ち上げる、立ち上がっていればフォーカスを与えるようにする。

いろいろ試したけど、vbsのWscript.ShellのAppActivateで電卓にフォーカスを与えることができず。
メモ帳とかはOK。UWPだから?
仕方ないので、適当な電卓ソフトを探してきて、設置。

VBSを準備

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Const strCalcExe = "BunCalc.exe" 'プロセス名
 
call ActiveCalc
 
sub ActiveCalc()
    Dim objWshShell
    Dim calcID
    
    calcID=GetProcID(strCalcExe)
 
 
    'MsgBox calcID
 
    Set objWshShell = CreateObject("Wscript.Shell")
 
    IF calcID = 0 Then
       strCmdLine = "D:\nonInstallPrograms\BunCalc\BunCalc.exe"
       Set objExecCmd = objWshShell.Exec(strCmdLine)
    Else
       objWshShell.AppActivate calcID
    End If
 
 
    Set objWshShell = Nothing
End Sub
 
Function GetProcID(ProcessName)
    Dim Service
    Dim QfeSet
    Dim Qfe
    Dim RetInt
 
    Set Service = WScript.CreateObject("WbemScripting.SWbemLocator").ConnectServer
    Set QfeSet = Service.ExecQuery("Select * From Win32_Process Where Caption='"& ProcessName &"'")
 
    RetInt = 0
    
    For Each Qfe in QfeSet
        RetInt =  Qfe.ProcessId
        Exit For
    Next
 
    GetProcID = RetInt
End Function
Const strCalcExe = "BunCalc.exe" 'プロセス名

call ActiveCalc
 
sub ActiveCalc()
    Dim objWshShell
    Dim calcID
    
    calcID=GetProcID(strCalcExe)


    'MsgBox calcID

    Set objWshShell = CreateObject("Wscript.Shell")

    IF calcID = 0 Then
       strCmdLine = "D:\nonInstallPrograms\BunCalc\BunCalc.exe"
       Set objExecCmd = objWshShell.Exec(strCmdLine)
    Else
       objWshShell.AppActivate calcID
    End If


    Set objWshShell = Nothing
End Sub
 
Function GetProcID(ProcessName)
    Dim Service
    Dim QfeSet
    Dim Qfe
    Dim RetInt
 
    Set Service = WScript.CreateObject("WbemScripting.SWbemLocator").ConnectServer
    Set QfeSet = Service.ExecQuery("Select * From Win32_Process Where Caption='"& ProcessName &"'")

    RetInt = 0
    
    For Each Qfe in QfeSet
        RetInt =  Qfe.ProcessId
        Exit For
    Next
 
    GetProcID = RetInt
End Function

キーの割り当ては、レジストリ。
電卓ボタンは18番らしい。
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18
文字列値を新規で追加する

名前 ShellExecute
値 VBSファイルの絶対パス

コメントを残す

メールアドレスが公開されることはありません。


*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" extra="">