#author("2019-01-14T16:49:47+09:00","","")
#navi(../)
* ファイルを開いているユーザを特定する・openfiles [#mfdd347d]
コマンドプロンプトを''管理者''として実行し、openfilesコマンドを実行するとプロセスがどのファイルを開いているかを特定できます。~
以下に使用方法を記します。

#contents
#htmlinsertpcsp(win-top.html,win-sp.html)

* openfilesコマンドを実行してみる [#hea99b9d]
openfilesコマンドは、管理者としてコマンドプロンプトを起動して使います。~
普通に起動すると以下のメッセージが表示されます。
 Microsoft Windows [Version 6.1.7601]
 Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
 
 C:\Users\sakura>openfiles
 エラー: ログオンしているユーザーは管理者特権を持っていません。
 
 C:\Users\sakura>

以下、管理者としてコマンドプロンプトを起動し、openfilesコマンドを実行したときの出力です。
 Microsoft Windows [Version 6.1.7601]
 Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
 
 C:\Windows\system32>openfiles
 
 情報: ローカルで開いたファイルを参照するには、システム グローバル フラグ
       'maintain objects list' を有効にする必要があります。
       詳細情報は、Openfiles /? を参照してください。
 
 
 ローカルの共有ポイントをとおしてリモートで開いているファイル:
 ---------------------------------------------
 
 情報: 開いている共有ファイルが見つかりませんでした。
 
 C:\Windows\system32>

* maintain objects listを有効にする [#s52151e7]
上記でopenfilesを実行し以下のメッセージが表示されたら、maintain objects listを有効にしなければなりません。
 情報: ローカルで開いたファイルを参照するには、システム グローバル フラグ
       'maintain objects list' を有効にする必要があります。
       詳細情報は、Openfiles /? を参照してください。

上記のメッセージに従い、openfiles /?を実行すると以下のメッセージが表示されました。
 C:\Windows\system32>openfiles /?
 
 OPENFILES /parameter [引数]
 
 説明:
     システム上の開いているファイルとフォルダーを管理者が
     切断できるようにします。
 
 パラメーターの一覧:
     /Disconnect    1 つ以上の開いているファイルを切断します。
 
     /Query         ローカルまたは共有フォルダーで開いているファイルを表示
                    します。
 
     /Local         ローカルで開いているファイルの表示を有効/無効にします。
 
     /?             このヘルプのメッセージを表示します。
 
 例:
     OPENFILES /Disconnect /?
     OPENFILES /Query /?
     OPENFILES /Local /?

上記の例:に記されている構文を実行すると各オプションの説明を見ることができます。~
今回は、Query, Localの2を確認してみます。
-Query
 C:\Windows\system32>openfiles /query /?
 
 OPENFILES /Query [/S システム [/U ユーザー名 [/P [パスワード]]]]
                  [/FO 形式] [/NH] [/V]
 
 説明:
     リモートから開かれたシステム上のファイルとフォルダーの一覧を
     表示できるようにします。
 
 パラメーターの一覧:
     /S      システム             接続先のリモート システムを指定します。
 
 <省略>
 
 例:
    OPENFILES /Query /?
    OPENFILES /Query
    OPENFILES /Query /FO csv /NH
    OPENFILES /Query /FO LIST /V
    OPENFILES /Query /S システム /U ユーザー名 /P パスワード /NH

-Local
 C:\Windows\system32>openfiles /local /?
 
 OPENFILES /Local [ ON | OFF ]
 
 説明:
     ローカルのファイル ハンドル追跡するシステム グローバル
     フラグ'maintain objects list' を、管理者が有効/無効にでき
     るようになります。このスイッチによる変更は、システムを
     再起動した後にのみ有効になります。
 
     注意: このフラグを有効にすると、パフォーマンスに負荷がかかります。
 
 パラメーターの一覧:
     /?                           このヘルプのメッセージを表示します。
 
 例:
     OPENFILES /Local /?
     OPENFILES /Local
     OPENFILES /Local ON
     OPENFILES /Local OFF

上記の説明を確認すると、maintain objects listを有効にするには、以下のオプションを実行すれば有効になるのがわかります。~
また、maintain objects listを有効にした後は再起動が必要であることもわかります。
 openfiles /local on


* maintain objects listを有効にしopenfilesコマンドを実行してみる [#yc60baaa]
上記でmaintain objects listを有効にする方法を記しました。~
maintain objects listが有効になる、以下のコマンドを実行し、Windowsを再起動しました。 
 openfiles /local on

上記のコマンドを実行したときの出力は以下の通りです。
 C:\Windows\system32>openfiles /local on
 
 成功: システム グローバル フラグ 'maintain objects list' は有効になりました。
       システムを再起動すると、変更が有効になります。

再起動後、以下のようにopenfilesコマンドを実行するとmaintain objects listが有効になっているのが確認できます。
 C:\Windows\system32>openfiles /local
 
 情報: システム グローバル フラグ 'maintain objects list' は、現在有効です。

maintain objects listを無効にする場合は、以下の構文になります。
 openfiles /local off

** openfilesコマンドを実行してみる [#ab7d7896]
以下にopenfilesを使った例を記します。~
オプション/queryを使った例も記しています。詳細は openfiles /query /? で使いかたを調べてみてください。

openfilesコマンドをオプションなしで実行すると、以下の出力のように、プロセス名とそのプロセスが開いているファイル一覧が表示されます。
 C:\Windows\system32>openfiles
 ローカルで開いているファイル:
 ---------------------
 
 ID    プロセス名           開いているファイル (パス\実行可能ファイル)        
 ===== ==================== ==================================================
 12    taskhost.exe         C:\Windows\System32
 48    taskhost.exe         C:\Windows\System32\ja-JP\taskhost.exe.mui
 224   taskhost.exe         C:\..1e18e3b_9.0.30729.6161_none_08e61857a83bc251
 232   taskhost.exe         C:\..1e18e3b_9.0.30729.6161_none_08e61857a83bc251
 292   taskhost.exe         C:\Windows\System32\ja-JP\MsCtfMonitor.dll.mui
 536   taskhost.exe         C:\Windows\System32\ja-JP\KernelBase.dll.mui
 692   taskhost.exe         C:\Windows\System32\ja-JP\msutb.dll.mui
 732   taskhost.exe         C:\Windows\System32\ja-JP\winmm.dll.mui
 12    dwm.exe              C:\Windows\System32
 <省略>

詳細な情報を確認したい場合は、/query /V オプションをつかうと取得することができます。
 openfiles /query /V
実際に実行した出力結果は以下の通りです。~
プロセスID、アクセスユーザなどが表示されているのがわかります。
C:\Windows\system32>openfiles /query /V

ローカルで開いているファイル:
---------------------

ID    アクセス        PID      プロセス名           開いているファイル (パス\実行可能ファイル)                                      
===== ============ ======== ==================== ================================================================================
12    sakura          2624     taskhost.exe         C:\Windows\System32
48    sakura          2624     taskhost.exe         C:\Windows\System32\ja-JP\taskhost.exe.mui
224   sakura          2624     taskhost.exe         C:\Windows\winsxs\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251
232   sakura          2624     taskhost.exe         C:\Windows\winsxs\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251
292   sakura          2624     taskhost.exe         C:\Windows\System32\ja-JP\MsCtfMonitor.dll.mui
536   sakura          2624     taskhost.exe         C:\Windows\System32\ja-JP\KernelBase.dll.mui
692   sakura          2624     taskhost.exe         C:\Windows\System32\ja-JP\msutb.dll.mui
732   sakura          2624     taskhost.exe         C:\Windows\System32\ja-JP\winmm.dll.mui
12    sakura          2800     dwm.exe              C:\Windows\System32
 C:\Windows\system32>openfiles /query /V
 
 ローカルで開いているファイル:
 ---------------------
 
 ID    アクセス        PID      プロセス名           開いているファイル (パス\実行可能ファイル)                                      
 ===== ============ ======== ==================== ================================================================================
 12    sakura          2624     taskhost.exe         C:\Windows\System32
 48    sakura          2624     taskhost.exe         C:\Windows\System32\ja-JP\taskhost.exe.mui
 224   sakura          2624     taskhost.exe        C:\Windows\winsxs\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251
 232   sakura          2624     taskhost.exe         
C:\Windows\winsxs\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251
 292   sakura          2624     taskhost.exe         C:\Windows\System32\ja-JP\MsCtfMonitor.dll.mui
 536   sakura          2624     taskhost.exe         C:\Windows\System32\ja-JP\KernelBase.dll.mui
 692   sakura          2624     taskhost.exe         C:\Windows\System32\ja-JP\msutb.dll.mui
 732   sakura          2624     taskhost.exe         C:\Windows\System32\ja-JP\winmm.dll.mui
 12    sakura          2800     dwm.exe              C:\Windows\System32
 <省略>

上記コマンドを実行すると出力される内容が多いので、moreやファイルへ出力すると便利でしょう。~
また、findstrなどを利用して特定のキーワードで探すと便利です。

出力形式をcsvにすることなどもできます。
 openfiles /query /FO csv
上記のオプションでopenfilesを実行するとcsv形式で出力されます。~
実際に実行した出力結果です。
 C:\Windows\system32>openfiles /query /FO csv > \Users\sakura\Desktop\openfiles.csv
作成されたcsvファイルをExcelで開いたときのスクリーンショットです。
#ref(of-01.gif)

以下、Microsofft Word文章を開き、コマンドプロンプトを管理者として実行しopenfilesコマンドとfindstrコマンドを実行したときの出力になります。~
findstrにWord文章のファイル名を指定しopenfilesの出力から検索しています。~

 C:\Windows\system32>openfiles | findstr /C:"Microsoft Word 文書.docx"
 1216  WINWORD.EXE          C:\Users\sakura\Desktop\Microsoft Word 文書.docx

 C:\Windows\system32>openfiles /query /V | findstr /C:"Microsoft Word 文書.docx"
 1216  sakura       3204     WINWORD.EXE          C:\Users\sakura\Desktop\Microsoft Word 文書.docx

findstrコマンドの使用方法については、以下のリンクで記事を公開しています。
-[[正規表現で文字列検索をする・findstr>コマンドプロンプト/正規表現で文字列検索をする・findstr]]

#htmlinsertpcsp(win-btm.html,win-sp.html)



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS