110,538
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog=new OpenFileDialog();
openFileDialog.InitialDirectory="c:\\";
openFileDialog.Filter="dll文件(*.dll)|*.*";
openFileDialog.RestoreDirectory=true;
openFileDialog.FilterIndex=1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if(openFileDialog.FileName.ToLower().Contains(".dll")==false)//.Substring(openFileDialog.FileName.IndexOf('.')).ToString().ToLower()!=".dll")
{
MessageBox.Show("必须是dll文件!");
return;
}
textBox1.Text = openFileDialog.FileName;
// 这里为你要注册的DLL地址
string DLLPath = textBox1.Text;
string Path = Environment.SystemDirectory;
Path = Path + @"\..\Microsoft.NET\Framework\v2.0.50727\Regasm.exe";
if (File.Exists(Path))
{
string result = RunExec(Path, DLLPath);
if (result.IndexOf("成功注册了类型") != -1)
MessageBox.Show("注册成功!");
else
MessageBox.Show(" 注册失败!");
}
else
MessageBox.Show("系统中 Regasm.exe 不存在!");
}
}
string RunExec(string path, string para)
{
System.Diagnostics.ProcessStartInfo Pros = new System.Diagnostics.ProcessStartInfo();
Pros.FileName = path;
Pros.Arguments = para;
System.Diagnostics.Process Pro = new System.Diagnostics.Process();
Pro.StartInfo = Pros;
Pro.StartInfo.RedirectStandardOutput = true;
Pro.StartInfo.UseShellExecute = false;
Pro.Start();
string result = Pro.StandardOutput.ReadToEnd();
Pro.Close();
Pro.Dispose();
return result;
}
不知道我说清楚没有,客户端安装该安装程序的时候,就做上面的三个事情