怎么把EXE文件嵌在正在编写的程序里,并对他执行复制到指定目录的操作。

解决方案 »

  1.   

    添加一个Resource1.resx文件,然后使用“添加资源”--》“添加现在文件”
    我这里把系统自带的Notepad.exe加了进来
      
           private bool WriteFile(byte[] pReadByte, string FileName)
            {
                FileStream fs = null;
                try
                {
                    fs = new FileStream(FileName, FileMode.OpenOrCreate);
                    fs.Write(pReadByte, 0, pReadByte.Length);
                }
                catch(Exception ex)         
                {
                    MessageBox.Show(ex.Message);
                    return false;
                }
                finally
                {
                    if (fs != null)
                        fs.Close();            }
                return true;
            }        private void button1_Click(object sender, EventArgs e)
            {
                System.Reflection.Assembly myAssembly;
                myAssembly = this.GetType().Assembly;            //WindowsApplication1.Resource1 得修改成你的工程名称.资源文件名称
                System.Resources.ResourceManager myManager = new System.Resources.ResourceManager("WindowsApplication1.Resource1", myAssembly);            try
                {
                    byte[] byteNotepad = (byte[])myManager.GetObject("notepad");
                    WriteFile(byteNotepad, @"d:\\Notepad.exe");
                    System.Diagnostics.Process.Start(@"d:\\Notepad.exe");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }           
            }