Using ssh to add register key on ssh server

Hi,

I want to use ssh to add a register key on remote ssh server. Since there are space characters in my register key string, it always failed. If there is no space characters in the string, it worked fine. The following is what I have tried. It seems that "ssh" command doesn't care about double quotes, it just ignores them. Does anyone know how to make it work?

Thanks!

 C:\>ssh ADM_B REG ADD "HKLM\Software\My Co" /v
cat /t REG_SZ /d 100 /f
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.

C:\>ssh ADM_B "REG ADD \"HKLM\Software\My Co\"
/v cat /t REG_SZ /d 100 /f"
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.

C:\>ssh ADM_B REG ADD \'HKLM\Software\My Co\' /v
 cat /t REG_SZ /d 100 /f
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.

C:\>ssh ADM_B REG ADD 'HKLM\Software\My Co' /v
cat /t REG_SZ /d 100 /f
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.

C:\>ssh ADM_B REG ADD HKLM\Software\MyCo /v cat
 /t REG_SZ /d 100 /f
The operation completed successfully.

The ssh command does care about double quotes, if it sees them. But cmd.exe doesn't build the arguments right. It doesn't even allow you to escape anything (as you tried) since the backslash is used as path separator.

Thank you for reply! So I have to find an alternative to make it work.

---------- Post updated at 12:01 PM ---------- Previous update was at 09:43 AM ----------

I tried to add the register key on server locally. There is no problem when I ran "REG ADD..." directly under command line with space characters in the register key string.

C:\>REG ADD "HKLM\Software\My Co" /v Data /t REG_BINARY /d fe340ead
The operation completed successfully.

Or if I run ssh to login my ssh server ADM_B first and then run the command above, it still works fine.

C:\>ssh ADM_B
Last login: Wed Dec  2 15:36:28 2009 from adm_p
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\cygwin\home\AspectRoot>REG ADD "HKLM\Software\My Co" /v cat /t REG_SZ /d 100 /f
The operation completed successfully.

What is the difference between running "ssh" and "REG ADD" in two steps and running both in one command line on client?

Thanks!

The biggest question is why are you running windows as your OS

In your two examples, this is what REG sees as it's arguments:

  1. ADD
  2. HKLM\Software\My Co
  3. /v
  4. Data
  5. /t
  6. REG_SZ
  7. /d
  8. 100
  9. /f

However, since to the Windows "shell" being very, very, very limited and not allowing nested quotes, this is what your ssh command looks like:

  1. ADM_B
  2. REG
  3. ADD
  4. HKLM\Software\My
  5. Co
  6. /v
  7. cat
  8. /t
  9. REG_SZ
  10. /d
  11. 100
  12. /f

But since you've apparently got Cygwin installed anyways, use the Bash shell that's installed with it, since this shell knows about different types of quotes and how to nest them.

I am not well versed with Powershell, but why don't you look into using that? The commands are probably more robust for windows.

What happens if you try

ssh ADM_B 'REG ADD "HKLM\Software\My Co" /vcat /t REG_SZ /d 100 /f'

It also failed.

C:\>ssh ADM_B 'REG ADD "HKLM\Software\My Co" /v cat /t REG_SZ /d 100 /f'
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.

---------- Post updated at 11:25 AM ---------- Previous update was at 10:42 AM ----------

I tried to run the same command line under Bash shell. But it still failed and got the same result. It seems that double quotes are needed, but ssh still doesn't like space character.

bash-3.2$ ssh ADM_B REG ADD "HKLM\Software\My Co" /v cat /t REG_SZ /d 100 /f
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.

bash-3.2$ ssh ADM_B REG ADD "HKLM\Software\MyCo" /v cat /t REG_SZ /d 100 /f
The operation completed successfully.

bash-3.2$ ssh ADM_B REG ADD HKLM\Software\MyCo /v cat /t REG_SZ /d 100 /f
ERROR: Invalid key name.
Type "REG ADD /?" for usage.

Try

ssh ADM_B REG ADD "HKLM\Software\My\ Co" /v cat /t REG_SZ /d 100 /f

It failed too.

bash-3.2$ ssh ADM_B REG ADD "HKLM\Software\My\ Co" /v cat /t REG_SZ /d 100 /f
ERROR: Invalid syntax.
Type "REG ADD /?" for usage.