Demo_C#_Winform 压缩、解压缩

本文介绍了如何在C# Winform应用中调用WinRAR进行文件的压缩和解压缩操作。首先,通过注册表获取WinRAR的exe路径,然后使用Process类配置ProcessStartInfo并设置RAR命令参数,实现对WinRAR命令的调用。
摘要由CSDN通过智能技术生成

由于版本更新需要,研究了下调用WinRAR软件进行解压缩。

  1. 获取WinRAR应用程序路径:通过注册表,获取exe路径;我的Win10是"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe"。其他系统不知道有没有变化,可以自己打开注册表去检查下。
  2. 创建Process类操作WinRAR应用程序:配置好ProcessStartInfo参数(在ProcessStartInfo参数中可以对Arguments 的赋值,传入RAR命令符)
  3. 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();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值