System.Environment.SystemDirectory
可能会把System32显示出来,再去除吧

解决方案 »

  1.   

    不好意思啊,我没看清楚楼主的意思,要获取Windows的路径可以调用API(GetWindowsDirectory),下面给出可以直接编译运行的代码,楼主参考参考using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Text;
    using System.Runtime.InteropServices; //调用API必须要把这个加上namespace GetWindows
    {
    public class Form1 : System.Windows.Forms.Form
    {
    [DllImport("kernel32")]
    public static extern void GetWindowsDirectory(StringBuilder WinDir,int count); private System.Windows.Forms.Button btnsend;
    private System.Windows.Forms.Label WindowsDirectory; private System.ComponentModel.Container components = null; public Form1()
    {
    InitializeComponent(); }
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码 private void InitializeComponent()
    {
    this.btnsend = new System.Windows.Forms.Button();
    this.WindowsDirectory = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // btnsend
    // 
    this.btnsend.Location = new System.Drawing.Point(192, 208);
    this.btnsend.Name = "btnsend";
    this.btnsend.Size = new System.Drawing.Size(104, 24);
    this.btnsend.TabIndex = 0;
    this.btnsend.Text = "发送";
    this.btnsend.Click += new System.EventHandler(this.button1_Click);
    // 
    // WindowsDirectory
    // 
    this.WindowsDirectory.Location = new System.Drawing.Point(96, 72);
    this.WindowsDirectory.Name = "WindowsDirectory";
    this.WindowsDirectory.Size = new System.Drawing.Size(336, 48);
    this.WindowsDirectory.TabIndex = 1;
    this.WindowsDirectory.Text = "label1";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(544, 318);
    this.Controls.Add(this.WindowsDirectory);
    this.Controls.Add(this.btnsend);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false); }
    #endregion [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void button1_Click(object sender, System.EventArgs e)
    {

    const int nChars = 128;
    StringBuilder Buff = new StringBuilder(nChars);
    GetWindowsDirectory(Buff,nChars);
    WindowsDirectory.Text = "Windows路径:"+Buff.ToString();

    } private void Form1_Load(object sender, System.EventArgs e)
    {

    }
    }
    }
      

  2.   

    // Sample for the Environment.SystemDirectory property
    using System;class Sample 
    {
        public static void Main() 
        {
        Console.WriteLine();
    //  <-- Keep this information secure! -->
        Console.WriteLine("SystemDirectory: {0}", Environment.SystemDirectory);
        }
    }
    /*
    This example produces the following results:SystemDirectory: C:\WINNT\System32
    */
      

  3.   

    麻烦各位老大看清楚楼主的意思啊,他要的是windows目录所在地,而不是System目录所在,虽然可以事后再处理,但多麻烦啊!
      

  4.   

    二楼说的对
    System.Environment.SystemDirectory;
      

  5.   

    System.Environment.GetEnvironmentVariable();这个东东肯定能解决楼主的问题了
    对了,参数是 windir
      

  6.   

    我要用程序运行WINDOWS里面的计算器直接用户不去修改path里面的路径,
    直接写calc.exe就能运行。
    System.Environment.GetEnvironmentVariable("windir");  
      

  7.   

    System.Environment.GetEnvironmentVariable("windir");
      

  8.   

    Environment.GetEnvironmentVariable("windir");
    直接调用 calc.exe 不就可以使用计算器了吗