wuyq11(人生如梦) 的方法是安装部署自定义安装类
System.Diagnostics.Process.Start("1.bat");   
Process p = new Process();
  p.StartInfo.FileName = "1.bat"; //设定程序名
    
  p.StartInfo.UseShellExecute = false;   
  p.StartInfo.RedirectStandardInput = true;   
  p.StartInfo.RedirectStandardOutput = true;   
  p.StartInfo.RedirectStandardError = true;   
  p.StartInfo.CreateNoWindow = true;   
  p.Start();   
  p.StandardInput.WriteLine(@"");
  p.StandardInput.WriteLine("exit"); 那么我新建了一个类库,在类库里添加了一个安装程序类,下面我就不知道该怎么做了。这段代码写在哪?另外如何设定路径,在这个类文件里无法引用using System.Windows.Forms;所以也无法写Application.StartupPath 

解决方案 »

  1.   

    意思是自己写一个exe文件,然后文件调用.bat  。将安装、注册之类的操作写在bat里面
      

  2.   

    生成exe可执行程序后,程序调用.bat
      

  3.   

    嗯,我现在会写了,但出现了一个问题,我没法指定bat文件的路径,我想设置为安装目录,但这个类文件里无法引用using System.Windows.Forms;所以也无法写Application.StartupPath 
      

  4.   

    为什么无法using?添加这个dll引用不就可以了吗?
      

  5.   

    吼吼,要手动引用才可以啊,我之前都是直接在上面写的using,所以没成功,我现在写成这样  base.Install(stateSaver);
                System.Diagnostics.Process.Start(Application.StartupPath + @"\reg.bat");
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = "reg.bat"; //设定程序名            p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                p.Start();
                p.StandardInput.WriteLine(@"");
                p.StandardInput.WriteLine("exit");
    按道理应该是在我安装目录下找reg了,可为什么每次都要在system32下找呢?只要system32下有reg就可以注册成功,没有就报“系统找不到指定的文件”
      

  6.   

    或者我怎么样做才能在安装时将reg拷入到system32下?
      

  7.   

    你用windows services来控制
    这样会执行的
      

  8.   

    试试:
    System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + @"\reg.bat");
      

  9.   

    System.Diagnostics.Process.Start(AppDomain.CurrentDomain.BaseDirectory + @"\reg.bat");一样的,只要system32下有reg就可以注册成功,没有就报“系统找不到指定的文件”
      

  10.   

    在安装项目的自定义操作 将属性CustomActionData的值等于/installdir="[TARGETDIR]\"
    然后在安装类   string filePath = Context.Parameters["installdir"] + "reg.bat";获得安装路径
    参考代码:
      string filePath = Context.Parameters["installdir"] + "reg.bat";
                    ProcessStartInfo info = new ProcessStartInfo(filePath);
                    info.WorkingDirectory = Context.Parameters["installdir"];
                    info.UseShellExecute = false;
                    info.CreateNoWindow = true;
                    Process p = Process.Start(info);
      

  11.   

    参考官网
    http://msdn.microsoft.com/zh-cn/library/d9k65z2d.aspx