Environment.SpecialFolder.CommonApplicationData
Environment.SpecialFolder.CommonApplicationData
private void button1_Click(object sender, EventArgs e)
{
var path=Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
MessageBox.Show(“路径:”+path);
var dir = path + “\edutools\“;
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
Process.Start(“explorer.exe”,dir);
}
private void button2_Click(object sender, EventArgs e)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
MessageBox.Show("路径:" + path);
var dir = path + "\\edutools\\";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
Process.Start("explorer.exe",dir);
}
private void button3_Click(object sender, EventArgs e)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
MessageBox.Show("路径:" + path);
var dir = path + "\\edutools\\";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
Process.Start("explorer.exe",dir);
}
private void button4_Click(object sender, EventArgs e)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.System);
MessageBox.Show("路径:" + path);
var dir = path + "\\edutools\\";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
Process.Start("explorer.exe", dir);
}
private void button5_Click(object sender, EventArgs e)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
MessageBox.Show("路径:" + path);
var dir = path + "\\edutools\\";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
Process.Start("explorer.exe", dir);
}
private void button6_Click(object sender, EventArgs e)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
MessageBox.Show("路径:" + path);
var dir = path + "\\edutools\\";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
Process.Start("explorer.exe", dir);
}
测试结果:
在未授予Administrator权限的的Win7 32位上(不打勾,表示无法创建成功):
Environment.SpecialFolder.CommonApplicationData
https://www.dearcloud.cn/2015/02/03/20200310-cnblogs-old-posts/20150203-Environment.SpecialFolder.CommonApplicationData/