c#调用dos命令

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;
        }
 }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值