0
Takeown  /f  D:\Windows /r  /D Y

Takeown  /f   "D:\Program Files"  /r  /D Y

Takeown  /f   "D:\Program Files(x86)"  /r  /D Y

Attrib  -s  -r  -h  D:\ProgramData

Takeown  /f   D:\ProgramData  /r  /D Y

Icacls  D:\Windows  /grant  %Username%:F   /t   /c

Icacls  "D:\Program Files"  /grant  %Username%:F   /t   /c

Icacls  "D:\Program Files(x86)"   /grant  %Username%:F   /t   /c

Icacls  D:\ProgramData  /grant  %Username%:F   /t   /c

I want later to be able to get acces to each command as a string for example:

"Icacls  "D:\Program Files(x86)"   /grant  %Username%:F   /t   /c"

I can make:

string[] params = new string[] {....};

But i'm getting messed up with the directories since some of them have to be between commas like: "D:\Program Files"

So far i tried this:

string[] commands = new string[] {
        "Takeown  /f  D:\\Windows /r  /D Y", "Takeown  /f   ""D:\Program Files""\  /r  /D Y"};

But getting errors on the part: "D:\Program Files""\ /r /D Y"

Syntax error, ',' expected Unrecognized escape sequence Error ',' expected Unrecognized escape sequence

Daniel Lip
  • 3,867
  • 7
  • 58
  • 120
  • 1
    What have you tried and what is the issue you are facing ? – Shyju Oct 22 '17 at 21:32
  • Possible duplicate of [How do I escape " in verbatim string?](https://stackoverflow.com/questions/17168961/how-do-i-escape-in-verbatim-string) – John Wu Oct 22 '17 at 21:41

1 Answers1

3

Since double quotation marks conflict with string markup, you need to escape them. You can escape double quotation marks (as well as any other special symbol) by adding \ in front. For example: var str = "foo \"bar\"".

In your context that would look like: string[] parameters = new string[] { "Icacls \"D:\Program Files(x86)\" /grant %Username%:F /t /c" };

P.S. params is a reserved keyword and cannot be used as a variable name.