How to capture running instance of an application ?
-
Dear All, Please help me in solving my problem. I have a windows application called "CallProcess", in it I have two TextBoxes on the form. I also have a method called display(), In this method I am creating a File and writing the text entered in the textBox into the file. Following is the code snippet, public void Display() { StreamWriter sw = new StreamWriter(@"c:\shutdown.txt", true); sw.WriteLine(textBox1.Text); sw.WriteLine(textBox2.Text); sw.WriteLine("Data written after execution of textbox data"); sw.Close(); } Now I want to access this method in other windows application, I am writing the following code snippet, try { Process[] BPDProcesses = Process.GetProcessesByName "CallProcess"); foreach (Process BPDProcess in BPDProcesses) { Console.WriteLine(BPDProcess.HasExited.ToString()); string ModuleName = "CallProcess.exe"; string TypeName = "Form1"; string MethodName = "Display"; Assembly BPDAssembly = Assembly.LoadFrom BPDProcess.MainModule.FileName.ToString()); BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly); Module[] BPDModules = BPDAssembly.GetModules(); foreach (Module BPDModule in BPDModules) { if (BPDModule.Name == ModuleName) { Type[] BPDTypes = BPDModule.GetTypes(); foreach (Type BPDType in BPDTypes) { if (BPDType.Name == TypeName) { MethodInfo[] BPDMethodInfo = BPDType.GetMethods(flags); foreach (MethodInfo BPDMethod in BPDMethodInfo) { if (BPDMethod.Name == MethodName) { try { Object obj = Activator.CreateInstance(BPDType);
-
Dear All, Please help me in solving my problem. I have a windows application called "CallProcess", in it I have two TextBoxes on the form. I also have a method called display(), In this method I am creating a File and writing the text entered in the textBox into the file. Following is the code snippet, public void Display() { StreamWriter sw = new StreamWriter(@"c:\shutdown.txt", true); sw.WriteLine(textBox1.Text); sw.WriteLine(textBox2.Text); sw.WriteLine("Data written after execution of textbox data"); sw.Close(); } Now I want to access this method in other windows application, I am writing the following code snippet, try { Process[] BPDProcesses = Process.GetProcessesByName "CallProcess"); foreach (Process BPDProcess in BPDProcesses) { Console.WriteLine(BPDProcess.HasExited.ToString()); string ModuleName = "CallProcess.exe"; string TypeName = "Form1"; string MethodName = "Display"; Assembly BPDAssembly = Assembly.LoadFrom BPDProcess.MainModule.FileName.ToString()); BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly); Module[] BPDModules = BPDAssembly.GetModules(); foreach (Module BPDModule in BPDModules) { if (BPDModule.Name == ModuleName) { Type[] BPDTypes = BPDModule.GetTypes(); foreach (Type BPDType in BPDTypes) { if (BPDType.Name == TypeName) { MethodInfo[] BPDMethodInfo = BPDType.GetMethods(flags); foreach (MethodInfo BPDMethod in BPDMethodInfo) { if (BPDMethod.Name == MethodName) { try { Object obj = Activator.CreateInstance(BPDType);