想做个小程序,读取本地机器的内存大小,然后把数据写到另外一台机器的ini文件中。请给个简单的提示啊,新手。
机器的内存应该很好读 你查一下资料
远程的操作还不会
读写ini文件到是知道一些
using System.Runtime.InteropServices;
using System.Text;
调用API函数
//API函数调用
//注:filePath是绝对路径
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def,StringBuilder retVal, int size, string filePath);
//写入INI文件
private void button2_Click(object sender, System.EventArgs e)
{
string FileName = textBox1.Text;
string section = textBox2.Text;
string key = textBox3.Text;
string keyValue = textBox4.Text;
WritePrivateProfileString(section, key, keyValue, FileName);
MessageBox.Show("成功写入INI文件!", "信息");
}
//读取指定INI文件的特定段落中的关键字的数值
private void button3_Click(object sender, System.EventArgs e)
{
StringBuilder temp = new StringBuilder(255);
string FileName = textBox1.Text;
string section = textBox2.Text;
string key = textBox3.Text;
int i = GetPrivateProfileString(section, key,
"无法读取对应数值!", temp, 255, FileName);
//显示读取的数值
textBox4.Text = temp.ToString();
}