public static void SimulateInstall()

in Microsoft.Diagnostics.Tracing/EventSource/EventSource/30_EventLogEventSource.cs [150:204]


        public static void SimulateInstall(string destFolder, string eventSourceName= "", bool prompt = true)
        {
            Out.WriteLine("Simulating the steps needed to register the EventSource with the OS");
            Out.WriteLine("These steps are only needed for Windows Event Log support.");
            Out.WriteLine("Admin privileges are needed to do this, so you will see elevation prompts");
            Out.WriteLine("If you are not already elevated.  Consider running from an admin window.");
            Out.WriteLine();

            if (prompt)
            {
                Out.WriteLine("Press <Enter> to proceed with installation");
                Console.ReadLine();
            }

            Out.WriteLine("Deploying EventSource to {0}", destFolder);
            // create deployment folder if needed
            if (Directory.Exists(destFolder))
            {
                Out.WriteLine("Error: detected a previous deployment.   Cleaning it up.");
                SimulateUninstall(destFolder, false);
                Out.WriteLine("Done Cleaning up orphaned installation.");
            }

            Out.WriteLine("Copying the EventSource manifest and compiled Manifest DLL to target directory.");
            Directory.CreateDirectory(destFolder);
            var sourceFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            foreach (var filename in Directory.GetFiles(sourceFolder, "*" + eventSourceName + "*.etwManifest.???"))
            {
                var destPath =  Path.Combine(destFolder, Path.GetFileName(filename));
                Out.WriteLine("xcopy \"{0}\" \"{1}\"", filename, destPath);
                File.Copy(filename, destPath, true);
            }

            Out.WriteLine("Registering the manifest with the OS (Need to be elevated)");
            foreach (var filename in Directory.GetFiles(destFolder, "*.etwManifest.man"))
            {
                var commandArgs = string.Format("im {0} /rf:\"{1}\" /mf:\"{1}\"",
                    filename,
                    Path.Combine(destFolder, Path.GetFileNameWithoutExtension(filename) + ".dll"));

                // as a precaution uninstall the manifest.   It is easy for the demos to not be cleaned up 
                // and the install will fail if the EventSource is already registered.   
                Process.Start(new ProcessStartInfo("wevtutil.exe", "um" + commandArgs.Substring(2)) { Verb = "runAs" }).WaitForExit();
                Thread.Sleep(200);          // just in case elevation makes the wait not work.  

                Out.WriteLine("  wevtutil " + commandArgs);
                // The 'RunAs' indicates it needs to be elevated. 
                // Unfortunately this also makes it problematic to get the output or error code.  
                Process.Start(new ProcessStartInfo("wevtutil.exe", commandArgs) { Verb = "runAs" }).WaitForExit();
            }

            System.Threading.Thread.Sleep(1000);
            Out.WriteLine("Done deploying app.");
            Out.WriteLine();
        }