gpt4 book ai didi

c# - 如何在 C# 中导出注册表

转载 作者:行者123 更新时间:2023-11-30 19:10:40 25 4
gpt4 key购买 nike

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

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 参数后添加一个空格,这样您的代码将是:

private static void Export(string exportPath, string registryPath)
{
string path = "\""+ exportPath + "\"";
string key = "\""+ registryPath + "\"";
using (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)
{
// handle exceptions
}
}
}

关于c# - 如何在 C# 中导出注册表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16316827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com