0

I am trying to remove old certificates from the os so i wrote a method for that:

    public ActionResult DeleteOldCertificates(Session session)
    {
        try
        {
            return (DeleteAutority(session) == ActionResult.Success 
                ? Delete2018(session) == ActionResult.Success 
                    ? ActionResult.Success : ActionResult.Failure 
                : ActionResult.Failure);
        }
        catch (Exception ex)
        {
            session.Log(ex.Message);
            return ActionResult.Failure;
        }
    }

    public ActionResult Delete2018(Session session)
    {
        try
        {
            var constants = new Constants(session);

            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute = false;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = $"/C CERTUTIL.exe -delstore MY Loi2018";
            startInfo.Verb = "runas";
            process.StartInfo = startInfo;
            process.Start();

            process.WaitForExit();

            session.Log($"Delete2018 ExitCode: {process.ExitCode}");
            session.Log($"Delete2018 Message: {process.StandardOutput.ReadToEnd()}");

            return process.ExitCode != 0 ? ActionResult.Failure : ActionResult.Success;
        }
        catch (Exception ex)
        {
            session.Log(ex.Message);
            return ActionResult.Failure;
        }
    }
    public ActionResult DeleteAutority(Session session)
    {
        try
        {
            var constants = new Constants(session);

            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute = false;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = $"/C CERTUTIL.exe -delstore -enterprise root Autority";
            startInfo.Verb = "runas";
            process.StartInfo = startInfo;
            process.Start();

            process.WaitForExit();

            session.Log($"DeleteAutority ExitCode: {process.ExitCode}");
            session.Log($"DeleteAutority Message: {process.StandardOutput.ReadToEnd()}");

            return process.ExitCode != 0 ? ActionResult.Failure : ActionResult.Success;
        }
        catch (Exception ex)
        {
            session.Log(ex.Message);
            return ActionResult.Failure;
        }
    }

Unfortunatelly during execution I am receiving error:

Message: Administrator permissions are needed to use the selected options.  Use an administrator command prompt to complete these tasks.

CertUtil: The requested operation requires elevation.

On the windows 7 this code works. On the Windows server 2012 if i use rmb and then run as admin then it is working if I just double click then not

user I am running this is in local admins group

3
  • @damagedCoda as I wrote in the question I need to check this on w7 and windows server 2012 and I only have problems with windows server 2012 Commented Feb 28, 2019 at 11:44
  • Damn my bad. So sorry. Commented Feb 28, 2019 at 11:57
  • Do refer to this post, it does not have a solution but i think it can help you understand your problem better. Commented Feb 28, 2019 at 12:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.