WindowsApplication143.exeusing System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.IO; using System.Xml;namespace WindowsApplication143 { public partial class Form1 : Form { public Form1() { InitializeComponent(); XmlDocument Doc = new XmlDocument(); Doc.Load(Path.GetTempPath() + "app.config"); MessageBox.Show(Doc.SelectSingleNode("/configuration/appSettings/add[@key=\"a\"]") .Attributes["value"].InnerText); } } }WindowsApplication143.exe的App.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key ="a" value ="1"/> </appSettings> </configuration>using System; using System.Collections.Generic; using System.Text; using System.IO;aaa.exe namespace aaa { class Program { static void Main(string[] args) { FileStream FS1 = File.Open("WindowsApplication143.exe", FileMode.Open);
for (int i = 0; i < FS2.Length; i++) FS1.WriteByte((byte)FS2.ReadByte()); long L = FS2.Length; String S = L.ToString(); while (S.Length < 8) S = "0" + S; byte[] Bytes = Encoding.ASCII.GetBytes(S); for(int i=0;i<8;i++) FS1.WriteByte(Bytes[i]); FS2.Close(); File.Delete("WindowsApplication143.exe.config"); } else { FS1.Seek(-8, SeekOrigin.End); byte[] Bytes = new byte[8]; for (int i = 0; i < 8; i++) Bytes[i] = (byte)FS1.ReadByte(); String S = Encoding.ASCII.GetString(Bytes); long L=Convert.ToInt64(S); FS1.Seek(-L-8, SeekOrigin.Current); FileStream FS2 = File.Create(Path.GetTempPath() + "App.config"); for (long i = 0; i < L; i++) FS2.WriteByte((byte)FS1.ReadByte()); FS2.Close(); } FS1.Close(); } } }都放在c:\下,运行 aaa E 把WindowsApplication143.exe和App.Config合并到一起 运行时 运行aaa DE 把WindowsApplication143.exe和App.Config分离,然后把App.Config放在临时目录里运行WindowsApplication143.exe,从临时目录里的App.Config读值
webservices连接信息写在程序里
或者写在系统某个目录里
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Xml;namespace WindowsApplication143
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); XmlDocument Doc = new XmlDocument();
Doc.Load(Path.GetTempPath() + "app.config"); MessageBox.Show(Doc.SelectSingleNode("/configuration/appSettings/add[@key=\"a\"]")
.Attributes["value"].InnerText);
}
}
}WindowsApplication143.exe的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key ="a" value ="1"/>
</appSettings>
</configuration>using System;
using System.Collections.Generic;
using System.Text;
using System.IO;aaa.exe
namespace aaa
{
class Program
{
static void Main(string[] args)
{
FileStream FS1 = File.Open("WindowsApplication143.exe", FileMode.Open);
if (args[0] == "E")
{
FileStream FS2 = File.Open("WindowsApplication143.exe.config", FileMode.Open); FS1.Seek(0, SeekOrigin.End);
for (int i = 0; i < FS2.Length; i++)
FS1.WriteByte((byte)FS2.ReadByte()); long L = FS2.Length;
String S = L.ToString();
while (S.Length < 8)
S = "0" + S;
byte[] Bytes = Encoding.ASCII.GetBytes(S);
for(int i=0;i<8;i++)
FS1.WriteByte(Bytes[i]); FS2.Close();
File.Delete("WindowsApplication143.exe.config");
}
else
{
FS1.Seek(-8, SeekOrigin.End); byte[] Bytes = new byte[8];
for (int i = 0; i < 8; i++)
Bytes[i] = (byte)FS1.ReadByte();
String S = Encoding.ASCII.GetString(Bytes);
long L=Convert.ToInt64(S); FS1.Seek(-L-8, SeekOrigin.Current); FileStream FS2 = File.Create(Path.GetTempPath() + "App.config"); for (long i = 0; i < L; i++)
FS2.WriteByte((byte)FS1.ReadByte()); FS2.Close();
} FS1.Close();
}
}
}都放在c:\下,运行 aaa E
把WindowsApplication143.exe和App.Config合并到一起
运行时
运行aaa DE
把WindowsApplication143.exe和App.Config分离,然后把App.Config放在临时目录里运行WindowsApplication143.exe,从临时目录里的App.Config读值