批量注册reg,dll,ocx组件
批量注册reg,dll,ocx组件
/// <summary>
/// 获取文件列表
/// dir 文件夹
/// type 文件类型:如ocx,reg,dll
/// </summary>
/// <returns>文件名列表</returns>
private string[] getFileList(String dir, String type)
{
return System.IO.Directory.GetFiles(dir, type, System.IO.SearchOption.TopDirectoryOnly);
}
/// <summary>
/// 注册文件
/// </summary>
/// <param name="fileList"></param>
/// <returns></returns>
private void registerTheFile(string[] fileList)
{
//功能切换
if (btnStart.Text.Equals("开始注册"))
{
btnStart.Text = "停止注册";
}
else
{
btnStart.Text = "开始注册";
}
//创建注册线程
if (null == registerThread || System.Threading.ThreadState.Stopped == registerThread.ThreadState)
{
registerThread = new Thread(delegate()
{
for (int i = 0; i < progBarRegister.Maximum; ++i)
{
if (btnStart.Text.Equals("开始注册"))
{
break;
}
Process p = new Process();
p.StartInfo.FileName = "Regsvr32.exe";//进程名,调用regsvr32.exe
p.StartInfo.Arguments = " /s " + "\"" + fileList[i] + "\"";// /s 表示不显示出控制台窗体
p.Start();
setTextSafe(rtbInfo, (i + 1) + "/" + progBarRegister.Maximum + "\r" + fileList[i]);
progBarRegister_setValue(i + 1); //更新进度条
}
});
}
progBarRegister.Maximum = fileList.Length;
progBarRegister.Value = 0;
//若线程正在执行
if (registerThread.IsAlive)
{
return;
}
registerThread.Start();
}