Esempio n. 1
0
        private string GetMessageLibraryNames(string libRegKey)
        {
            string      str = null;
            RegistryKey key = null;

            try
            {
                key = GetSourceRegKey(this.owner.Log, this.Source, this.owner.MachineName);
                if (key != null)
                {
                    str = (string)key.GetValue(libRegKey);
                }
            }
            finally
            {
                if (key != null)
                {
                    key.Close();
                }
            }
            if (str == null)
            {
                return(null);
            }
            if (!(this.owner.MachineName != "."))
            {
                return(str);
            }
            string[]      strArray = str.Split(new char[] { ';' });
            StringBuilder builder  = new StringBuilder();

            for (int i = 0; i < strArray.Length; i++)
            {
                if (strArray[i].EndsWith("EventLogMessages.dll", StringComparison.Ordinal))
                {
                    builder.Append(EventLog.GetDllPath("."));
                    builder.Append(';');
                }
                else if ((strArray[i].Length >= 2) && (strArray[i][1] == ':'))
                {
                    builder.Append(@"\\");
                    builder.Append(this.owner.MachineName);
                    builder.Append(@"\");
                    builder.Append(strArray[i][0]);
                    builder.Append("$");
                    builder.Append(strArray[i], 2, strArray[i].Length - 2);
                    builder.Append(';');
                }
            }
            if (builder.Length == 0)
            {
                return(null);
            }
            return(builder.ToString(0, builder.Length - 1));
        }
Esempio n. 2
0
        // ------------------------------------------------------------------------------
        // Returns DLL names list.
        // libRegKey can be: "EventMessageFile", "CategoryMessageFile", "ParameterMessageFile"
        private string GetMessageLibraryNames(string libRegKey)
        {
            // get the value stored in the registry

            //Remote EventLog libraries cannot be retrieved unless the source
            //also exists on the local machine. For entries written using this
            //particular API, we can retrieve the local messages library and
            //return the correct information.
            string      fileName = null;
            RegistryKey regKey   = null;

            try {
                regKey = GetSourceRegKey(logName, Source, ".");
                if (regKey != null)
                {
                    fileName = (string)regKey.GetValue(libRegKey);
                }
                else if (ownerMachineName != ".")
                {
                    try {
                        regKey = GetSourceRegKey(logName, Source, ownerMachineName);
                    }
                    catch (Exception) {
                    }

                    if (regKey != null)
                    {
                        string remoteFileName = (string)regKey.GetValue(libRegKey);
                        if (remoteFileName.EndsWith(EventLog.DllName))
                        {
                            fileName = EventLog.GetDllPath(".");
                        }
                    }
                }
            }
            finally {
                if (regKey != null)
                {
                    regKey.Close();
                }
            }

            // convert any environment variables to their current values
            // (the key might have something like %systemroot% in it.)
            return(TranslateEnvironmentVars(fileName));
        }