-1

I'm trying to add a value to the registry which contains spaces and for that reason i want to retain double quotes.

I've tried escaping double quotes with '\"' but this had no effect

path_with_spaces = "C:\Users\me\i have space\app.exe"
argument_with_spaces = "Quick brown fox"

data = '"{}" -n "{}"'.format(path_with_spaces, argument_with_spaces)
command = 'REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /f /v test /d "{}"'.format(data)
subprocess.call(command)

if i print "command" i get:

REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /f /v test /d ""C:\Users\me\i have space\app.exe" -n "Quick brown fox""

but there are no double quotes to be seen while inspecting the result with regedit. Even if i do this:

data = '\"{}\" -n \"{}\"'.format(path_with_spaces, argument_with_spaces)

There is no change. The output when inspecting with regedit is always like this:

C:\Users\me\i have space\app.exe -n Quick brown fox

What am i doing wrong?

sparky
  • 375
  • 6
  • 22

1 Answers1

1

When you inject the data variable in the command variable, it is already a string. So If you wand to keep the\ in the command, you have to double them in the data declaration

I think you could try something like this:

data = '\\"{}\\" -n \\"{}\\"'.format(path_with_spaces, argument_with_spaces)
Maaz
  • 2,405
  • 1
  • 15
  • 21