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位上(不打勾,表示无法创建成功):
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。