現在のプロセスのファイル名を取得しようとしています。
つまり、「test.txt」というファイルをメモ帳で開いている場合、「c:\folder\test.txt」のようなものを取得する必要があります。
以下のコードは、ソフトウェア パスを含むプロセス情報を返します。(例: "c:\windows\system32\notepad.exe")。
[DllImport("user32.dll", EntryPoint = "GetForegroundWindow", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int GetForegroundWindow();
[...]
public static string GetFilePathName()
{
uint procId = 0;
int hWnd = GetForegroundWindow();
GetWindowThreadProcessId(hWnd, out procId);
var proc = Process.GetProcessById((int)procId);
}
このプロセス クラスを使用して、現在のプロセスが処理している開いているファイル名/パスを取得することは可能ですか?