I found this question because I was looking for something a little bit different. I need to put quotes into the thing I'm setting. This isn't exactly what the OP is asking about but may be related if the problem is embedded quotation marks.
setx SVN_EDITOR C:\Program Files\vim\vim74\vim.exe
I found that this, while "correct", doesn't work because the user of this variable gets tripped by the space in the path so I needed to put quotes in there.
I found that
set SVN_EDITOR="C:\Program Files\vim\vim74\vim.exe"
worked just fine so I thought I'd try the normal way of escaping quotes on Windows:
setx SVN_EDITOR "^"C:\Program Files\vim\vim74\vim.exe^""
but this didn't work, resulting in the error:
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.
So I just opened system settings in the control panel and set the value in the environment variables GUI. Works fine now, I can type set svn
at the command line and it shows quoted as I need it to be.
If you really need to set your environment variable programatically you'll need to look at banging on the registry yourself. This is pretty straight forward in both C and Python (and probably in other languages too). It doesn't seem as though setx
can do it for you though.