checking in latest Yaulw
This commit is contained in:
@@ -9,6 +9,12 @@ namespace _app
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
//var Running = Yaulw.Win32.COM.GetActiveObjects("");
|
||||||
|
//var RunningExcelWorkbooks = Yaulw.Win32.COM.GetRunningObjects();
|
||||||
|
|
||||||
|
//int n1 = Running.Count();
|
||||||
|
//int n2 = RunningExcelWorkbooks.Count();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
51
Win32/COM.cs
51
Win32/COM.cs
@@ -21,6 +21,19 @@ namespace Yaulw.Win32
|
|||||||
[DllImport("ole32.dll")]
|
[DllImport("ole32.dll")]
|
||||||
public static extern int CreateBindCtx(int reserved, out IBindCtx ppbc);
|
public static extern int CreateBindCtx(int reserved, out IBindCtx ppbc);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a pointer to the IRunningObjectTable
|
||||||
|
/// interface on the local running object table (ROT).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="reserved">This parameter is reserved and must be 0.</param>
|
||||||
|
/// <param name="prot">The address of an IRunningObjectTable* pointer variable
|
||||||
|
/// that receives the interface pointer to the local ROT. When the function is
|
||||||
|
/// successful, the caller is responsible for calling Release on the interface
|
||||||
|
/// pointer. If an error occurs, *pprot is undefined.</param>
|
||||||
|
/// <returns>This function can return the standard return values E_UNEXPECTED and S_OK.</returns>
|
||||||
|
[DllImport("ole32.dll")]
|
||||||
|
public static extern int GetRunningObjectTable(uint reserved, out System.Runtime.InteropServices.ComTypes.IRunningObjectTable pprot);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use this to retrieve the Actice COM Object from the ROT, for the specified progId
|
/// Use this to retrieve the Actice COM Object from the ROT, for the specified progId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -46,6 +59,42 @@ namespace Yaulw.Win32
|
|||||||
public object o;
|
public object o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all Running Objects in the ROT (deos the same thing as GetRunningObjects())
|
||||||
|
/// ~got code snippet from a different website. keeping it in Just in case
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MonikerFilter"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static List<RunningObject> GetActiveObjects(string MonikerFilter)
|
||||||
|
{
|
||||||
|
var ret = new List<RunningObject>();
|
||||||
|
|
||||||
|
IRunningObjectTable pprot;
|
||||||
|
IEnumMoniker ppenumMoniker;
|
||||||
|
IMoniker[] monikers = new IMoniker[1];
|
||||||
|
|
||||||
|
GetRunningObjectTable(0, out pprot);
|
||||||
|
pprot.EnumRunning(out ppenumMoniker);
|
||||||
|
ppenumMoniker.Reset();
|
||||||
|
|
||||||
|
while (ppenumMoniker.Next(1, monikers, IntPtr.Zero) == 0)
|
||||||
|
{
|
||||||
|
IBindCtx ctx;
|
||||||
|
CreateBindCtx(0, out ctx);
|
||||||
|
|
||||||
|
string name;
|
||||||
|
monikers[0].GetDisplayName(ctx, null, out name);
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(MonikerFilter) || (name.IndexOf(MonikerFilter) != -1))
|
||||||
|
{
|
||||||
|
object val;
|
||||||
|
pprot.GetObject(monikers[0], out val);
|
||||||
|
ret.Add(new RunningObject() { name = name, o = val });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use this to Get All Running Objects in the ROT
|
/// Use this to Get All Running Objects in the ROT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -72,6 +121,8 @@ namespace Yaulw.Win32
|
|||||||
{
|
{
|
||||||
RunningObject running;
|
RunningObject running;
|
||||||
monikers[0].GetDisplayName(bc, null, out running.name);
|
monikers[0].GetDisplayName(bc, null, out running.name);
|
||||||
|
Type ff1 = monikers[0].GetType();
|
||||||
|
|
||||||
runningObjectTable.GetObject(monikers[0], out running.o);
|
runningObjectTable.GetObject(monikers[0], out running.o);
|
||||||
res.Add(running);
|
res.Add(running);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using diag = System.Diagnostics;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using SysIO = System.IO;
|
using SysIO = System.IO;
|
||||||
@@ -330,6 +331,52 @@ namespace Yaulw.Win32
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Process / Handle Functionallity
|
||||||
|
|
||||||
|
public static string GetProcessName(IntPtr hWnd)
|
||||||
|
{
|
||||||
|
int currentPid = 0;
|
||||||
|
User32.GetWindowThreadProcessId(hWnd, ref currentPid);
|
||||||
|
|
||||||
|
diag.Process process;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
process = diag.Process.GetProcessById(currentPid);
|
||||||
|
}
|
||||||
|
catch (ArgumentException e)
|
||||||
|
{
|
||||||
|
// This is thrown when Process.GetProcessById cannot find the process
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return process.ProcessName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the .Net Process Object that owns the passed in hWnd
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hWnd">handle to a Window</param>
|
||||||
|
/// <returns>a .Net Process or throws an error</returns>
|
||||||
|
public static diag.Process GetProcessFromHandle(IntPtr hWnd)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int currentPid = 0;
|
||||||
|
User32.GetWindowThreadProcessId(hWnd, ref currentPid);
|
||||||
|
|
||||||
|
diag.Process process;
|
||||||
|
process = diag.Process.GetProcessById(currentPid);
|
||||||
|
return process;
|
||||||
|
}
|
||||||
|
catch (ArgumentException e)
|
||||||
|
{
|
||||||
|
// This is thrown when Process.GetProcessById cannot find the process
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Short / Long FileName N' Path Conversions
|
#region Short / Long FileName N' Path Conversions
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user