Opc.Ua.Configuration.ConfigUtils.GetExecutablePath C# (CSharp) Method

GetExecutablePath() public static method

Returns the location of the COM server executable.
public static GetExecutablePath ( System.Guid clsid ) : string
clsid System.Guid
return string
		public static string GetExecutablePath(Guid clsid)
		{
			RegistryKey key = Registry.ClassesRoot.OpenSubKey(String.Format(@"CLSID\{{{0}}}\LocalServer32", clsid));

			if (key == null)
			{
				key	= Registry.ClassesRoot.OpenSubKey(String.Format(@"CLSID\{{{0}}}\InprocServer32", clsid));
			}

			if (key != null)
			{
				try
				{
					string codebase = key.GetValue("Codebase") as string;

					if (codebase == null)
					{
						return key.GetValue(null) as string;
					}

					return codebase;
				}
				finally
				{
					key.Close();
				}
			}

			return null;
		}

Usage Example

コード例 #1
0
        /// <summary>
        /// Returns the UA COM Pseudo-servers registered on the local computer.
        /// </summary>
        public static List <ConfiguredEndpoint> Enumerate()
        {
            // enumerate server clsids.
            List <Guid> clsids = ConfigUtils.EnumClassesInCategory(ConfigUtils.CATID_PseudoComServers);

            // initialize server objects.
            List <ConfiguredEndpoint> servers = new List <ConfiguredEndpoint>();

            for (int ii = 0; ii < clsids.Count; ii++)
            {
                ConfiguredEndpoint server = null;

                try {
                    server = Load(clsids[ii]);
                    servers.Add(server);
                } catch (Exception e) {
                    Utils.Trace(e, "Unexpected error loading psuedo-server: {0}", clsids[ii]);
                    continue;
                }

                // ensure the Pseudo-server points to the correct host process.
                Guid hostClsid = Guid.Empty;

                if (server.ComIdentity != null)
                {
                    hostClsid = GetServerHostClsid(server.ComIdentity.Specification);
                }

                string hostPath = ConfigUtils.GetExecutablePath(hostClsid);

                if (String.IsNullOrEmpty(hostPath))
                {
                    continue;
                }

                RegistryKey key =
                    Registry.ClassesRoot.OpenSubKey(String.Format(@"CLSID\{{{0}}}\LocalServer32", clsids[ii]), false);

                if (key != null)
                {
                    if (hostPath != (string)key.GetValue(null, ""))
                    {
                        try {
                            key.Close();
                            key = Registry.ClassesRoot.OpenSubKey(
                                String.Format(@"CLSID\{{{0}}}\LocalServer32", clsids[ii]), true);
                            key.SetValue(null, hostPath);
                        } catch (Exception) {
                            Utils.Trace("Could not update COM proxy server path for {0}.", server.ComIdentity.ProgId);
                        }
                    }

                    key.Close();
                }
            }

            return(servers);
        }
All Usage Examples Of Opc.Ua.Configuration.ConfigUtils::GetExecutablePath