如何在 Windows 7 上注册我编写的 dll?
我找到了这个代码片段,但它似乎在 Windows 7 中不起作用:
public static void registerDLL(string dllPath)
{
try {
//'/s' : indicates regsvr32.exe to run silently.
string fileinfo = "/s" + " " + "\"" + dllPath + "\"";
Process reg = new Process();
reg.StartInfo.FileName = "regsvr32.exe";
reg.StartInfo.Arguments = fileinfo;
reg.StartInfo.UseShellExecute = false;
reg.StartInfo.CreateNoWindow = true;
reg.StartInfo.RedirectStandardOutput = true;
reg.Start();
reg.WaitForExit();
reg.Close();
}
catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
最佳答案
工具“regsvr32.exe”只能注册 native COM-Dll。如果要注册用 C# 编写的 DotNet COM 对象,则必须改用“regasm.exe”。为此,您需要提升权限,因为它会写入注册表中的 HKEY_LOCAL_MACHINE。
关于c# - 在 C# 中在 Windows 7 上注册 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7401197/