是C#的,MSDN中的是VB的方法 没有看懂~!! 谢谢~!!

解决方案 »

  1.   

    你可以从Installer继承一个新的类,比如:Installer1,然后编写相应的重载方法,比如:
    protected override void OnCommitted(System.Collections.IDictionary savedState)
    {
        base.OnCommitted(savedState);
    }在这个方法里取得安装程序中用户选择的安装路径等信息来附加数据等.当然也可以添加自定义的Form来接受用户的输入信息.
    编写完Installer1的代码后编译程序,然后在安装项目中添加主输出项,添加自定义输出把新建立的安装项目DLL添加到安装项目中,这样程序在安装的时候就会自动的调用到Installer1里的C#代码了.
    比如下面的代码就是附加一个数据文件到SqlServer的:
    protected override void OnCommitted(System.Collections.IDictionary savedState)
    {
    try
    {
    string installDir = this.Context.Parameters["InstallDir"];
    FileInfo fi = new FileInfo(installDir);
    installDir = fi.DirectoryName;
    if (!installDir.EndsWith(@"\"))
    {
    installDir += @"\";
    }
    //检测数据库是否存在
    SqlConnection con = new SqlConnection("Data Source=.;Integrated Security=True");
    try
    {
    con.Open();
    SqlCommand cmd = con.CreateCommand();
    cmd.CommandText = "SELECT count(1) FROM master.dbo.sysdatabases where name = 'DBName'";
    object attach = cmd.ExecuteScalar();
    if (!object.Equals(attach, 1))
    {
    //不存在则附加数据库文件
    string dataBase = installDir + @"DataBase\";
    if (System.IO.Directory.Exists(dataBase))
    {
    cmd.CommandText = string.Format(@"EXEC sp_attach_db @dbname = N'Road_Cost', @filename1 = N'{0}'", dataBase + "DBFile.MDF");
    cmd.ExecuteNonQuery();
    }
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message, "查找数据库提示", MessageBoxButtons.OK);
    }
    finally
    {
    if (con != null)
    {
    con.Close();
    }
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    base.OnCommitted(savedState);
    }
      

  2.   

    hbxtlhx(平民百姓)
    说的方法值的一实
      

  3.   

    方法非常多:
    1、第三方安装布置工具,比如Wise、InstallShiled等来完成。
    2、自己写一个exe来完成,将它布置到客户机上,在安装完成后执行。
    3、通过vbs脚本来完成。
    4、在应用程序登录的时候进行数据库的配置。