由于版本更新需要,研究了下调用WinRAR软件进行解压缩。
- 获取WinRAR应用程序路径:通过注册表,获取exe路径;我的Win10是"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe"。其他系统不知道有没有变化,可以自己打开注册表去检查下。
- 创建Process类操作WinRAR应用程序:配置好ProcessStartInfo参数(在ProcessStartInfo参数中可以对Arguments 的赋值,传入RAR命令符)
- RAR命令符说明:随意打开WinRAR后可以查看相应的命令符说明
以下是封装的类
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DemoRAR
{
public class RARHelper
{
static string WinRARRegeditPath= @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe";
#region 私有方法
/// <summary>
/// 获取WinRAR应用程序路径,如果注册表中没有则返回当前目录下\res\WinRAR.exe
/// </summary>
/// <returns>返回注册表中指定的RAR应用程序路径,没有则返回当前目录下\res\WinRAR.exe</returns>
private string GetExePath()
{
RegistryKey the_Reg = Registry.LocalMachine.OpenSubKey(WinRARRegeditPath);//访问储存应用程序注册表信息键值
string exePath = the_Reg.GetValue("").ToString();