Plozy
Plozy

Reputation: 17

Run Command Prompt Commands can't run commands inside " "

i'm trying to run windows commands with this c# code:

Process cmd = new Process();
        cmd.StartInfo.FileName = "cmd.exe";
        cmd.StartInfo.RedirectStandardInput = true;
        cmd.StartInfo.RedirectStandardOutput = true;
        cmd.StartInfo.CreateNoWindow = false;
        cmd.StartInfo.UseShellExecute = false;
        cmd.Start();

        cmd.StandardInput.WriteLine("/C @shift /0");
        cmd.StandardInput.WriteLine("/C @echo off");
        cmd.StandardInput.WriteLine("/C color 04");
        cmd.StandardInput.WriteLine("/C title Loop Anti-Ban (Ignore Errors) (RGB)");
        cmd.StandardInput.WriteLine("/C :a");
        cmd.StandardInput.WriteLine("/C reg delete "HKEY_CURRENT_USER\Software\Epic Games\Unreal Engine\Identifiers" /f");
        cmd.StandardInput.Flush();
        cmd.StandardInput.Close();
        cmd.WaitForExit();
        Console.WriteLine(cmd.StandardOutput.ReadToEnd());

but it doesn't let me run cmd.StandardInput.WriteLine("/C reg delete "HKEY_CURRENT_USER\Software\Epic Games\Unreal Engine\Identifiers" /f");

No idea why... (another picture to be clear screenshot)

Upvotes: 0

Views: 105

Answers (1)

Access Denied
Access Denied

Reputation: 9461

You need to escape " in your string like this \" and \ in the path should be also escaped this way \\:

cmd.StandardInput.WriteLine("/C reg delete \"HKEY_CURRENT_USER\\Software\\Epic Games\\Unreal Engine\\Identifiers\\" /f");

Upvotes: 3

Related Questions