私はこのコードを使用しています:
Dim name
name = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%computername%")
Set wmi = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& name & "\root\cimv2")
For Each hwnd In wmi.InstancesOf("Win32_Process")
If hwnd.Name = "wscript.exe" Then
'get name and possibly location of currently running script
End If
Next
すべてのプロセスを正常にリストし、wscript.exe
. ただし、検索したところ、で実行されているスクリプトの名前を見つける方法が見つかりませんでしたwscript.exe
。それmyscript.vbs
かjscript.js
何かですか。スクリプトのパス全体を見つける方法があればボーナス。
編集:
さらに検索すると、解決策が見つかりました。上記のスクリプトでは、hwnd
変数はプロセスのハンドルを格納しwscript.exe
ます。ハンドルのプロパティがあります: hwnd.CommandLine
. コマンドラインから呼び出す方法を示しているので、次のようになります。
"C:\Windows\System32\wscript.exe" "C:\path\to\script.vbs"
そのため、文字列を解析して、hwnd.CommandLine
実行中のすべてのスクリプトのパスと名前を見つけることができます。