Probably you're calling setx
from bash
. Since \
is an escape character in bash and most other Unix shells, it won't result in a literal backslash. You need to escape the backslash itself with \
or quote it with '
:
$ echo setx -m HOME C:\Users\MyName
setx -m HOME C:UsersMyName
$ echo setx -m HOME 'C:\Users\MyName'
setx -m HOME C:\Users\MyName
$ echo setx -m HOME C:\\Users\\MyName
setx -m HOME C:\Users\MyName
Or just call setx
from a Windows shell like cmd or powershell. But as I said, if you need to call setx
from a script every time you run it then you're doing it wrong. In that case you need to use a normal set
:
set "HOME=%USERPROFILE%"