how to set a password on a rar file

5.6k Views Asked by At

I set a password on a rar file like this :

rar.exe a backup.rar c:\files -p123 -p- -k

this code set a password on my rar file and add file to it , but i do not know what is my password. this is my C# code :

p.StartInfo.FileName = System.Windows.Forms.Application.StartupPath + "\\Rar.exe";
p.StartInfo.Arguments = @"a backup.rar c:\files -p123 -p- -k";
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.Start();
p.WaitForExit();
2

There are 2 best solutions below

1
On

Please provide a link to the command-line switches available for the rar.exe that you're using, but in some Google searching, I found this:

-p[password] Set password

-p- Do not query password

Given that you have -p123, your password should be "123".

0
On

Here is an example which works well:

C:\Program Files\WinRAR>rar a -hpabc h:\abc.rar c:\pdf

So you can follow the example in your codes.

p.StartInfo.Arguments = String.Format("a -hp{0} {1} {2}", your password, Destination, SourceFile);
p.Start();