GetExePath() public static method

public static GetExePath ( ) : string
return string
Exemplo n.º 1
0
        private void menuFileOpenAsAdmin_Click(object sender, EventArgs e)
        {
            try
            {
                ProcessStartInfo start_info = new ProcessStartInfo(COMUtilities.GetExePath());
                start_info.UseShellExecute = true;
                start_info.Verb            = "runas";

                Process.Start(start_info).Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
 private void menuFileOpenViewer_Click(object sender, EventArgs e)
 {
     try
     {
         if (Environment.Is64BitProcess)
         {
             Process.Start(COMUtilities.Get32bitExePath()).Close();
         }
         else
         {
             Process.Start(COMUtilities.GetExePath()).Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private async static Task <InterfaceLists> GetInterfacesOOP(string command_line, bool runtime_class)
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(PipeDirection.In,
                                                                                    HandleInheritability.Inheritable, 16 * 1024, null))
            {
                string process = null;
                if (!Environment.Is64BitOperatingSystem || Environment.Is64BitProcess)
                {
                    process = COMUtilities.GetExePath();
                }
                else
                {
                    process = COMUtilities.Get32bitExePath();
                }

                Process          proc = new Process();
                ProcessStartInfo info = new ProcessStartInfo(process, string.Format("{0} {1} {2}",
                                                                                    runtime_class ? "-r" : "-e", server.GetClientHandleAsString(), command_line));
                info.UseShellExecute = false;
                info.CreateNoWindow  = true;
                proc.StartInfo       = info;
                proc.Start();
                try
                {
                    List <COMInterfaceInstance> interfaces         = new List <COMInterfaceInstance>();
                    List <COMInterfaceInstance> factory_interfaces = new List <COMInterfaceInstance>();
                    server.DisposeLocalCopyOfClientHandle();

                    using (StreamReader reader = new StreamReader(server))
                    {
                        while (true)
                        {
                            string line = await reader.ReadLineAsync();

                            if (line == null)
                            {
                                break;
                            }

                            if (line.StartsWith("ERROR:"))
                            {
                                uint errorCode;
                                try
                                {
                                    errorCode = uint.Parse(line.Substring(6), System.Globalization.NumberStyles.AllowHexSpecifier);
                                }
                                catch (FormatException ex)
                                {
                                    Debug.WriteLine(ex.ToString());
                                    errorCode = 0x80004005;
                                }

                                throw new Win32Exception((int)errorCode);
                            }
                            else
                            {
                                Guid g;
                                bool factory = false;

                                if (line.StartsWith("*"))
                                {
                                    factory = true;
                                    line    = line.Substring(1);
                                }

                                string[] parts = line.Split(new char[] { ',' }, 3);
                                if (Guid.TryParse(parts[0], out g))
                                {
                                    string module_path   = null;
                                    long   vtable_offset = 0;
                                    if (parts.Length == 3)
                                    {
                                        module_path = parts[1];
                                        long.TryParse(parts[2], out vtable_offset);
                                    }

                                    if (factory)
                                    {
                                        factory_interfaces.Add(new COMInterfaceInstance(g, module_path, vtable_offset));
                                    }
                                    else
                                    {
                                        interfaces.Add(new COMInterfaceInstance(g, module_path, vtable_offset));
                                    }
                                }
                            }
                        }

                        if (!proc.WaitForExit(5000))
                        {
                            proc.Kill();
                        }
                        int exitCode = proc.ExitCode;
                        if (exitCode != 0)
                        {
                            interfaces         = new List <COMInterfaceInstance>(new COMInterfaceInstance[] { new COMInterfaceInstance(COMInterfaceEntry.IID_IUnknown) });
                            factory_interfaces = new List <COMInterfaceInstance>(new COMInterfaceInstance[] { new COMInterfaceInstance(COMInterfaceEntry.IID_IUnknown) });
                        }
                        return(new InterfaceLists()
                        {
                            Interfaces = interfaces, FactoryInterfaces = factory_interfaces
                        });
                    }
                }
                finally
                {
                    proc.Close();
                }
            }
        }
Exemplo n.º 4
0
        public async static Task <COMEnumerateInterfaces> GetInterfacesOOP(COMCLSIDEntry ent)
        {
            using (AnonymousPipeServerStream server = new AnonymousPipeServerStream(System.IO.Pipes.PipeDirection.In,
                                                                                    HandleInheritability.Inheritable, 16 * 1024, null))
            {
                string process = null;
                if (!Environment.Is64BitOperatingSystem || Environment.Is64BitProcess)
                {
                    process = COMUtilities.GetExePath();
                }
                else
                {
                    process = COMUtilities.Get32bitExePath();
                }

                string apartment = "s";
                if (ent.DefaultThreadingModel == COMThreadingModel.Both ||
                    ent.DefaultThreadingModel == COMThreadingModel.Free)
                {
                    apartment = "m";
                }

                Process          proc = new Process();
                ProcessStartInfo info = new ProcessStartInfo(process, String.Format("{0} {1} {2} {3} \"{4}\"",
                                                                                    "-e", server.GetClientHandleAsString(), ent.Clsid.ToString("B"), apartment, ent.CreateContext));
                info.UseShellExecute = false;
                info.CreateNoWindow  = true;
                proc.StartInfo       = info;
                proc.Start();
                try
                {
                    server.DisposeLocalCopyOfClientHandle();

                    using (StreamReader reader = new StreamReader(server))
                    {
                        List <COMInterfaceInstance> interfaces         = new List <COMInterfaceInstance>();
                        List <COMInterfaceInstance> factory_interfaces = new List <COMInterfaceInstance>();
                        while (true)
                        {
                            string line = await reader.ReadLineAsync();

                            if (line == null)
                            {
                                break;
                            }

                            if (line.StartsWith("ERROR:"))
                            {
                                uint errorCode;
                                try
                                {
                                    errorCode = uint.Parse(line.Substring(6), System.Globalization.NumberStyles.AllowHexSpecifier);
                                }
                                catch (FormatException ex)
                                {
                                    Debug.WriteLine(ex.ToString());
                                    errorCode = 0x80004005;
                                }

                                throw new Win32Exception((int)errorCode);
                            }
                            else
                            {
                                Guid g;
                                bool factory = false;

                                if (line.StartsWith("*"))
                                {
                                    factory = true;
                                    line    = line.Substring(1);
                                }

                                string[] parts = line.Split(new char[] { ',' }, 3);
                                if (Guid.TryParse(parts[0], out g))
                                {
                                    string module_path   = null;
                                    long   vtable_offset = 0;
                                    if (parts.Length == 3)
                                    {
                                        module_path = parts[1];
                                        long.TryParse(parts[2], out vtable_offset);
                                    }

                                    if (factory)
                                    {
                                        factory_interfaces.Add(new COMInterfaceInstance(g, module_path, vtable_offset));
                                    }
                                    else
                                    {
                                        interfaces.Add(new COMInterfaceInstance(g, module_path, vtable_offset));
                                    }
                                }
                            }
                        }

                        if (!proc.WaitForExit(5000))
                        {
                            proc.Kill();
                        }
                        int exitCode = proc.ExitCode;
                        if (exitCode != 0)
                        {
                            interfaces         = new List <COMInterfaceInstance>(new COMInterfaceInstance[] { new COMInterfaceInstance(COMInterfaceEntry.IID_IUnknown) });
                            factory_interfaces = new List <COMInterfaceInstance>(new COMInterfaceInstance[] { new COMInterfaceInstance(COMInterfaceEntry.IID_IUnknown) });
                        }

                        return(new COMEnumerateInterfaces(ent.Clsid, ent.CreateContext, interfaces, factory_interfaces));
                    }
                }
                finally
                {
                    proc.Close();
                }
            }
        }