如何导出注册表在c# [英] How to export a registry in c#

查看:341
本文介绍了如何导出注册表在c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试导出并将注册表文件保存到任意位置,代码正在运行。但是,在指定路径和保存时,该功能不起作用,并且不会导出注册表。没有显示任何错误。

I have been trying to export and save registry files to an arbitrary location, the code is running. However, on specifying the path and saving, the function does not work and no registry is exported. There is no error shown either.

private static void Export(string exportPath, string registryPath)
{ 
    string path = "\""+ exportPath + "\"";
    string key = "\""+ registryPath + "\"";
    // string arguments = "/e" + path + " " + key + "";
    Process proc = new Process();

    try
    {
        proc.StartInfo.FileName = "regedit.exe";
        proc.StartInfo.UseShellExecute = false;
        //proc.StartInfo.Arguments = string.Format("/e", path, key);

        proc = Process.Start("regedit.exe", "/e" + path + " "+ key + "");
        proc.WaitForExit();
    }
    catch (Exception)
    {
        proc.Dispose();
    }
}


推荐答案

你需要在 / e 参数之后添加一个空格,以便您的代码将是:

You need to add a space after the /e parameters so your code will be :

private static void Export(string exportPath, string registryPath)
{ 
    string path = "\""+ exportPath + "\"";
    string key = "\""+ registryPath + "\"";
    Process proc = new Process();

    try
    {
        proc.StartInfo.FileName = "regedit.exe";
        proc.StartInfo.UseShellExecute = false;

        proc = Process.Start("regedit.exe", "/e " + path + " "+ key);
        proc.WaitForExit();
    }
    catch (Exception)
    {
        proc.Dispose();
    }
}

这篇关于如何导出注册表在c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆