System.Environment.SystemDirectory
可能会把System32显示出来,再去除吧
可能会把System32显示出来,再去除吧
解决方案 »
- (C#) (急) 如何获取.net自动创建的WORD对象
- sql数据库保存Excel报错,无效索引!!!!
- [在线等]怎么样在服务器端读取客户端post过来的XML数据啊?
- 大家帮忙 这样可以吗?
- 利用DataAdapter.Update()进行数据库更新的问题
- 散分+小小问题(发送消息给其他应用程序的窗体,并让其立即显示)
- 测试程序:不知那里的链接出错,单击链接的没反应
- 帮忙看一下,一段小代码,简单,50分全送!
- XmlNode 的 InnerText 和 Value 属性有什么不同?
- 为什么我用C#调用DLL总是报错:未处理的“System.Security.SecurityException”类型的异常出现在 system.windows.forms.dll 中
- [求助]请问怎样使鼠标移动到WindwosForm的边框时不会变成双向箭头也不能拖动边框来改变Form的大小?
- 关于在visual studio.net下c#编程的问题
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)
{
}
}
}
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
*/
System.Environment.SystemDirectory;
对了,参数是 windir
直接写calc.exe就能运行。
System.Environment.GetEnvironmentVariable("windir");
直接调用 calc.exe 不就可以使用计算器了吗