6

Here is code which I use to create a .rar file with a password

DECLARE @source VARCHAR(1000),
        @destination VARCHAR(1000),
        @Command VARCHAR(1000)

SET @source = 'E:\Temp\testRar.txt'
SET @destination = 'E:\Temp\testRar.rar'

SET @Command = '"C:\Program Files\WinRAR\Rar.exe"  a -ep1 -pasd^ad ' +@destination+' '+@source

EXEC MASTER..xp_cmdshell @Command

but it sets asdad password and not asd^ad, ^ symbol is ignored. Why?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
tungula
  • 578
  • 1
  • 6
  • 12

1 Answers1

3

The ^ character is an escape character in the command shell. Try doubling it up.

SET @Command = '"C:\Program Files\WinRAR\Rar.exe"  a -ep1 -pasd^^ad ' +@destination+' '+@source
Donal
  • 31,121
  • 10
  • 63
  • 72