C#+ VB:导入reg文件

时间:2018-06-04 06:34:31

标签: c# vb.net import registry

这里发现这个问题的答案很多,但是对于我来说它们似乎在Win10中不起作用...... C#

string RegFile = "some long path with spaces\file.reg";    
Process regeditProcess = Process.Start("regedit.exe", "/s \"" + RegFile + "\"");
regeditProcess.WaitForExit();

VB

Dim RegFile As String = "some long path with spaces\file.reg"
Process.Start("regedit.exe", "/s" & Chr(34) & RegFile & Chr(34))

尽管有/ s参数,这两种情况仍然会出现Regedit确认框。

1 个答案:

答案 0 :(得分:0)

问题可能来自UAC,并且没有正确的权限以静默方式启动注册表。

在某些安装过程中,可能还有 regedit.exe 文件可能已被修改或更改。

建议:

  • 以管理员身份运行程序

你也应该尝试:

Process.Start("regedit", "/s" & Chr(34) & RegFile & Chr(34))

并且

Process.Start("reg", "/s" & Chr(34) & RegFile & Chr(34))

我认为这应该直接调用windows中可能链接到另一个.exe的程序的引用,这就是为什么它可以使用这个版本。

如果其他人知道为什么reg /s选项有效而其他选项无效,请告诉我。