Run Command Prompt Commands can't run commands inside “ ”












0















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_USERSoftwareEpic GamesUnreal EngineIdentifiers" /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_USERSoftwareEpic GamesUnreal EngineIdentifiers" /f");



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










share|improve this question




















  • 1





    Hint: is an escape character. So t is interpreted as tab, r is interpreted as carriage return, n is interpreted as line feed, \ is interpreted as literal , etc.

    – John
    Dec 31 '18 at 14:55


















0















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_USERSoftwareEpic GamesUnreal EngineIdentifiers" /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_USERSoftwareEpic GamesUnreal EngineIdentifiers" /f");



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










share|improve this question




















  • 1





    Hint: is an escape character. So t is interpreted as tab, r is interpreted as carriage return, n is interpreted as line feed, \ is interpreted as literal , etc.

    – John
    Dec 31 '18 at 14:55
















0












0








0








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_USERSoftwareEpic GamesUnreal EngineIdentifiers" /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_USERSoftwareEpic GamesUnreal EngineIdentifiers" /f");



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










share|improve this question
















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_USERSoftwareEpic GamesUnreal EngineIdentifiers" /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_USERSoftwareEpic GamesUnreal EngineIdentifiers" /f");



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







c# windows command regedit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 14:59









Access Denied

5,12121643




5,12121643










asked Dec 31 '18 at 14:54









PlozyPlozy

51




51








  • 1





    Hint: is an escape character. So t is interpreted as tab, r is interpreted as carriage return, n is interpreted as line feed, \ is interpreted as literal , etc.

    – John
    Dec 31 '18 at 14:55
















  • 1





    Hint: is an escape character. So t is interpreted as tab, r is interpreted as carriage return, n is interpreted as line feed, \ is interpreted as literal , etc.

    – John
    Dec 31 '18 at 14:55










1




1





Hint: is an escape character. So t is interpreted as tab, r is interpreted as carriage return, n is interpreted as line feed, \ is interpreted as literal , etc.

– John
Dec 31 '18 at 14:55







Hint: is an escape character. So t is interpreted as tab, r is interpreted as carriage return, n is interpreted as line feed, \ is interpreted as literal , etc.

– John
Dec 31 '18 at 14:55














1 Answer
1






active

oldest

votes


















3














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");





share|improve this answer


























  • Did you try that? Those backslashes used as separators need to be escaped as well. (like "...USERSoft..." should be "...USER\Soft...")

    – Flydog57
    Dec 31 '18 at 15:05











  • @Flydog57 you are right, thank you for your comment.

    – Access Denied
    Dec 31 '18 at 15:08











  • A deeper problem is that we can't write "/C" command-line options to stdin of a single cmd.exe process. Write commands without "/C" that end in "rn" (CRLF). Set a unique prompt. After writing a command, use an inner loop to read lines from stdout until the prompt is read. Otherwise either the stdin or stdout pipe could fill up and block the child process (i.e. cmd.exe for internal commands, or a grandchild process such as reg.exe).

    – eryksun
    Dec 31 '18 at 21:24











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53988747%2frun-command-prompt-commands-cant-run-commands-inside%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














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");





share|improve this answer


























  • Did you try that? Those backslashes used as separators need to be escaped as well. (like "...USERSoft..." should be "...USER\Soft...")

    – Flydog57
    Dec 31 '18 at 15:05











  • @Flydog57 you are right, thank you for your comment.

    – Access Denied
    Dec 31 '18 at 15:08











  • A deeper problem is that we can't write "/C" command-line options to stdin of a single cmd.exe process. Write commands without "/C" that end in "rn" (CRLF). Set a unique prompt. After writing a command, use an inner loop to read lines from stdout until the prompt is read. Otherwise either the stdin or stdout pipe could fill up and block the child process (i.e. cmd.exe for internal commands, or a grandchild process such as reg.exe).

    – eryksun
    Dec 31 '18 at 21:24
















3














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");





share|improve this answer


























  • Did you try that? Those backslashes used as separators need to be escaped as well. (like "...USERSoft..." should be "...USER\Soft...")

    – Flydog57
    Dec 31 '18 at 15:05











  • @Flydog57 you are right, thank you for your comment.

    – Access Denied
    Dec 31 '18 at 15:08











  • A deeper problem is that we can't write "/C" command-line options to stdin of a single cmd.exe process. Write commands without "/C" that end in "rn" (CRLF). Set a unique prompt. After writing a command, use an inner loop to read lines from stdout until the prompt is read. Otherwise either the stdin or stdout pipe could fill up and block the child process (i.e. cmd.exe for internal commands, or a grandchild process such as reg.exe).

    – eryksun
    Dec 31 '18 at 21:24














3












3








3







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");





share|improve this answer















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");






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 31 '18 at 15:07

























answered Dec 31 '18 at 14:58









Access DeniedAccess Denied

5,12121643




5,12121643













  • Did you try that? Those backslashes used as separators need to be escaped as well. (like "...USERSoft..." should be "...USER\Soft...")

    – Flydog57
    Dec 31 '18 at 15:05











  • @Flydog57 you are right, thank you for your comment.

    – Access Denied
    Dec 31 '18 at 15:08











  • A deeper problem is that we can't write "/C" command-line options to stdin of a single cmd.exe process. Write commands without "/C" that end in "rn" (CRLF). Set a unique prompt. After writing a command, use an inner loop to read lines from stdout until the prompt is read. Otherwise either the stdin or stdout pipe could fill up and block the child process (i.e. cmd.exe for internal commands, or a grandchild process such as reg.exe).

    – eryksun
    Dec 31 '18 at 21:24



















  • Did you try that? Those backslashes used as separators need to be escaped as well. (like "...USERSoft..." should be "...USER\Soft...")

    – Flydog57
    Dec 31 '18 at 15:05











  • @Flydog57 you are right, thank you for your comment.

    – Access Denied
    Dec 31 '18 at 15:08











  • A deeper problem is that we can't write "/C" command-line options to stdin of a single cmd.exe process. Write commands without "/C" that end in "rn" (CRLF). Set a unique prompt. After writing a command, use an inner loop to read lines from stdout until the prompt is read. Otherwise either the stdin or stdout pipe could fill up and block the child process (i.e. cmd.exe for internal commands, or a grandchild process such as reg.exe).

    – eryksun
    Dec 31 '18 at 21:24

















Did you try that? Those backslashes used as separators need to be escaped as well. (like "...USERSoft..." should be "...USER\Soft...")

– Flydog57
Dec 31 '18 at 15:05





Did you try that? Those backslashes used as separators need to be escaped as well. (like "...USERSoft..." should be "...USER\Soft...")

– Flydog57
Dec 31 '18 at 15:05













@Flydog57 you are right, thank you for your comment.

– Access Denied
Dec 31 '18 at 15:08





@Flydog57 you are right, thank you for your comment.

– Access Denied
Dec 31 '18 at 15:08













A deeper problem is that we can't write "/C" command-line options to stdin of a single cmd.exe process. Write commands without "/C" that end in "rn" (CRLF). Set a unique prompt. After writing a command, use an inner loop to read lines from stdout until the prompt is read. Otherwise either the stdin or stdout pipe could fill up and block the child process (i.e. cmd.exe for internal commands, or a grandchild process such as reg.exe).

– eryksun
Dec 31 '18 at 21:24





A deeper problem is that we can't write "/C" command-line options to stdin of a single cmd.exe process. Write commands without "/C" that end in "rn" (CRLF). Set a unique prompt. After writing a command, use an inner loop to read lines from stdout until the prompt is read. Otherwise either the stdin or stdout pipe could fill up and block the child process (i.e. cmd.exe for internal commands, or a grandchild process such as reg.exe).

– eryksun
Dec 31 '18 at 21:24




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53988747%2frun-command-prompt-commands-cant-run-commands-inside%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas