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 GetWindowsDirectory
{
    public partial class Form1 : Form
    {
        [DllImport("kernel32.dll")]
        static extern uint GetWindowsDirectory(StringBuilder bufor, uint rozmiarBufora);

        private void button1_Click(object sender, EventArgs e)
        {
            const int MAX_PATH = 260;
            StringBuilder katalogWindows = new StringBuilder(MAX_PATH);
            uint rozmiar = (uint)katalogWindows.Capacity;
            GetWindowsDirectory(katalogWindows, rozmiar);
            MessageBox.Show(katalogWindows.ToString());
        }

        public Form1()
        {
            InitializeComponent();
        }
    }
}