-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (52 loc) · 2.22 KB
/
Program.cs
File metadata and controls
61 lines (52 loc) · 2.22 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Diagnostics;
using System.Collections.Generic;
using System;
namespace WindowTracker
{
/// <summary>
/// List of User32 Functions
/// http://www.pinvoke.net/default.aspx/user32.GetLastInputInfo
/// </summary>
class Program
{
static void Main(string[] args)
{
Process[] allProcesses = Process.GetProcesses();
List<string> processesToIgnore = new List<string>();
processesToIgnore.Add("explorer");
processesToIgnore.Add("ApplicationFrameHost");
string filename;
Microsoft.Office.Interop.Excel.Application excelApp;
Microsoft.Office.Interop.Word.Application wordApp;
ExcelInteropService eis = new ExcelInteropService();
WordInteropService wis = new WordInteropService();
foreach (Process proc in allProcesses)
{
if (proc.MainWindowHandle != IntPtr.Zero &&
!processesToIgnore.Contains(proc.ProcessName) &&
!String.IsNullOrWhiteSpace(proc.MainWindowTitle) &&
proc.Responding &&
WindowHelpers.WindowPlacementIsVisible(proc.MainWindowHandle))
{
Console.WriteLine(proc.ProcessName + proc.Id + proc.Responding + ": " + proc.MainWindowTitle + " (" + proc.MainWindowHandle.ToString() + ")");
filename = WindowHelpers.GetProcessFileName(proc);
Console.WriteLine(filename);
if (filename.ToLower().Contains("excel"))
{
excelApp = eis.GetOpenExcelApplication(proc);
Console.WriteLine(excelApp.ActiveWorkbook.FullName);
}
else if (filename.ToLower().Contains("word"))
{
wordApp = wis.GetOpenWordApplication(proc);
foreach (Microsoft.Office.Interop.Word.Document doc in wordApp.Documents)
{
Console.WriteLine(doc.FullName);
}
}
}
}
Console.ReadKey();
}
}
}