Example #1
0
        public TestConnectionResult TestConnection()
        {
            var result = new TestConnectionResult()
            {
                HostAndPort = this.HostAndPort
            };

            try
            {
                using (ProxyFileEnum serviceProxy = new ProxyFileEnum())
                {
                    serviceProxy.SetHost(HostAndPort);
                    serviceProxy.SetCredentials(GetCreds());
                    result.ServiceVersion = serviceProxy.ExchangeVersion(1);

                    if (result.ServiceVersion < 3)
                    {
                        // That's all we can get (the interface version).
                    }
                    else if (result.ServiceVersion < 5)
                    {
                        serviceProxy.GetServiceHostInfo(out result.HostExe, out result.HostVersion, out result.HostAccount);
                    }
                    else
                    {
                        // As of version 5, we can get whether or not the service is impersonating clients or not.
                        bool isImpersonating;
                        serviceProxy.GetServiceHostInfo2(out result.HostExe, out result.HostVersion, out result.HostAccount, out isImpersonating);
                        result.IsImpersonatingClients = isImpersonating;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Exception = ex;
            }

            return(result);
        }
Example #2
0
        // Determines if the specified port is in use by the TracerX service by attempting to connect to it.
        private static void TryConnecting(int port)
        {
            try
            {
                using (ProxyFileEnum serviceProxy = new ProxyFileEnum())
                {
                    serviceProxy.SetHost("localhost:" + port);
                    int serviceInterfaceVersion = serviceProxy.ExchangeVersion(1);

                    // Getting here without an exception means the TracerX service is listening on the port.
                    // Depending on the version, we may be able to get additional info.

                    if (serviceInterfaceVersion < 3)
                    {
                        // That's all we can get (the interface version).
                        MainForm.ShowMessageBox("The specified port is in use by another process that's running the TracerX service.");
                    }
                    else
                    {
                        string processExe;
                        string processVersion;
                        string processAccount;

                        if (serviceInterfaceVersion < 5)
                        {
                            serviceProxy.GetServiceHostInfo(out processExe, out processVersion, out processAccount);
                        }
                        else
                        {
                            // As of version 5, we can get whether the service is impersonating
                            // clients or not with GetServiceHostInfo2, but we don't need to.
                            serviceProxy.GetServiceHostInfo(out processExe, out processVersion, out processAccount);
                        }

                        string msg = "The specified port is in use by another process that's running the TracerX service.";

                        if (processExe != null)
                        {
                            msg += "\n\nExecutable: " + processExe;

                            if (processVersion != null)
                            {
                                msg += " (version " + processVersion + ")";
                            }
                        }

                        if (processAccount != null)
                        {
                            msg += "\n\nAccount: " + processAccount;
                        }

                        MainForm.ShowMessageBox(msg);
                    }
                }
            }
            catch (Exception ex)
            {
                // Assume this means the process using the port is not TracerX.
                MainForm.ShowMessageBox("The specified port is in use by another process.");
            }
        }