using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace InstallAll
{
/// <summary>
/// 安装 msde 程序 数据库
/// </summary>
class InstallAll
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
// //构造直接执行
string path = Application.StartupPath;
string strOdbc = GetBat();
System.Diagnostics.Process p = new Process();
// try
// {
// ps.StartInfo.UseShellExecute = true;
// ps.StartInfo.CreateNoWindow = true;
//
// ps.StartInfo.FileName = path + "//configure.bat";
// ps.Start();
// }
// catch(System.Exception ex)
// {
// ps.Close();
//
// }
try
{
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.StandardInput.WriteLine(strOdbc);
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
p.Close();
}
catch
{
p.Close();
}
}
private string GetBat()
{
string bat = "@echo 开始安装MSDE,请稍候..."+
"MSDE//Setup.exe /qb+ INSTANCENAME=TransinoBS DISABLENETWORKPROTOCOLS=1 SAPWD=TransinoBS securitymode=SQL"+
"@echo on"+
"@echo off"+
"@echo 开始安装Framework,请稍候..."+
"cd Framework"+
"dotnetfx.exe /Q"+
"langpack.exe /Q"+
"cd.."+
"@echo 正在重启MSDE服务,请稍候..."+
"net stop MSSQL$TransinoBS"+
"net start MSSQL$TransinoBS"+
"osql -E -S (local)//TransinoBS -Q /"if exists(select * from sysdatabases where name = 'TransinoBS') begin drop database TransinoBS end /" "+
"@echo 正在停止MSDE服务,请稍候..."+
"net stop MSSQL$TransinoBS"+
"@echo 开始创建文件目录,请稍候... "+
"if exist /"C://TransinoSvr/" Rd/S/Q /"C://TransinoSvr/" "+
"Md /"C://TransinoSvr///""+
"Md /"C://TransinoSvr//DATA///" "+
"Md /"C://TransinoSvr//Model///" "+
"Md /"C://TransinoSvr//IJ///" "+
"@echo 开始复制数据文件,请稍候..."+
"Copy /".//DATA///" /"C://TransinoSvr//DATA///" "+
"@echo 开始复制表单模板,请稍候..."+
"copy /".//Model//*.xls/" /"C://TransinoSvr//Model///""+
"@echo 开始恢复系统数据库,请稍候..."+
"net start MSSQL$TransinoBS"+
"osql -E -S (local)//TransinoBS -Q /"EXEC sp_attach_db @dbname = N'TransinoBS', @filename1 = N'C://TransinoSvr//DATA//TransinoBS.mdf', @filename2 = N'C://TransinoSvr//DATA//TransinoBS.ldf'/""+
"osql -E -S (local)//TransinoBS -Q /"use TransinoBS update MetaData set strParaValue = N'C://TransinoSvr//Model//' where strParaCode = 'RptModel'/" "+
"osql -E -S (local)//TransinoBS -Q /"use TransinoBS update MetaData set strParaValue = N'C://TransinoSvr//IJ//' where strParaCode = 'FileModel'/" "+
"@echo 正在配置ODBC系统数据源,请稍候..."+
"odbcconf.exe /a {CONFIGSYSDSN /"SQL Server/" /"DSN=TransinoBS|SERVER=(local)//TransinoBS|Database=TransinoBS/"} ";
return bat;
}
}
}