Reagcentc enable if its disabled by C# app

Kran2022 406 Reputation points
2023-03-06T08:27:29.4366667+00:00

Hi All: Morning

How can i write a c# application run once check the status of the Reagentc /info

At present i wrote a below bat command to enable recovery manually but i prefer doing it with an app automatically.

My question How can i write a c# app / console app check the status of the reagentc enable recovery if its disable? thanks

Bat command:

@echo EnableRecovery

ReAgentC /Enable

ReAgentC /Info

del %0

del /Q EnableRecovery.bat

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Jack J Jun 25,316 Reputation points
    2023-03-07T02:48:33.5833333+00:00

    @Kran2022, Welcome to Microsoft Q&A, you could try to use Process.StandardOutput to check if the reagentc is disable.

        internal class Program
        {
            static void Main(string[] args)
            {
                var proc = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName = "C:\\Windows\\System32\\ReAgentc.exe",
                        Arguments = "/info",
                        UseShellExecute = false,
                        RedirectStandardOutput = true,
                        CreateNoWindow = true
                    }
                };
                proc.Start();
                while (!proc.StandardOutput.EndOfStream)
                {
                    string line = proc.StandardOutput.ReadLine();
                    // do something with line
                    if(line.Contains("Windows RE status"))
                    {
                        if(line.Contains("Disabled"))
                        {
                            Process newp = new Process
                            {
                                StartInfo = new ProcessStartInfo
                                {
                                    FileName = "C:\\Windows\\System32\\ReAgentc.exe",
                                    Arguments = "/enable",
                                    UseShellExecute = false,
                                    RedirectStandardOutput = true,
                                    CreateNoWindow = false
                                }
                            };
                            newp.Start();
    
    
                        }
                    }
                   
                }
                Console.ReadKey();
            }
        }
    

    Tested result:

    User's image

    Hope my code could help you.

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.