/*建立一个Windows应用程序,上面添加一个按纽,单击事件为button1_Click*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace _01
{
    public partial class Form1 : Form
    {        [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);
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e) //一个按纽事件
        {
            string name = openfile();
            if (name != "")
            {
                MessageBox.Show(name);
                long s = WritePrivateProfileString("a", "key1", name, "./config.ini");  //这样将不会写入INI文件
            }        }        private string openfile()
        {
            OpenFileDialog temp = new OpenFileDialog();
            if (temp.ShowDialog() == DialogResult.OK)
                return temp.FileName;
            else return "";
        }
    }
}下午搞到现在才找出的问题,大家有没有这样的问题帮我试试,上面的代码如果是在VS2005中按F5运行,不会创建INI文件,如果到Debug目录下运行这个exe文件,就会创建ini文件,搞得头都大了。