这段代码只能获取在项目文件中的默认的bin文件夹下的debug文件夹里的文件我想问的是如何获取 比如C盘或D盘里的QQ文件夹下的QQ.EXE启动文件或别的文件夹下的文件呢...这段代码只能在项目中默认文件夹下使用,当用别的文件夹下的文件时会提示没有此文件或此文件不存在System.Diagnostics.Process.Start("用户手册.txt");请高手们看看呢该如何修改....
调试欢乐多
System.Diagnostics.Process.Start("C:\\用户手册.txt");
System.Diagnostics.Process.Start("QQ.EXE");,前面的路径我没有写,请问该如何加入路径,又该如何获取路径呢...
1.用openfiledialog来让用户自己找启动路径
2.遍历所有盘中的文件找到名称为“QQ.exe”的再获取路径启动,这个会费时间就比较多些了
的答案是正确 合理 的
获取路径后直接System.Diagnostics.Process.Start(@"获取的路径"+"\QQ.exe");
那如果是绿色版呢?所以还得是使用OpenFileDialog
{
string fullname = "C:\\QQ.EXE";
if(File.Exists(fullname))
{
}
else//如果不存在则查找
{
FolderBrowserDialog fbd=new FolderBrowserDialog();
fbd.ShowDialog(); string RootPath = fbd.SelectedPath;
if(Directory.Exists(RootPath))
{
DirectoryInfo d = new DirectoryInfo(RootPath); FileInfo[] FileList = d.GetFiles("QQ.exe", SearchOption.AllDirectories); if (FileList.Length > 0)
{
fullname = FileList[0].FullName;
}
else
{
MessageBox.Show("不存在此文件");
}
}
}
MessageBox.Show("QQ.exe的FullName为" + fullname);
}
2.遍历所有盘中的文件找到名称为“QQ.exe”的再获取路径启动,这个会费时间就比较多些了
private void button5_Click(object sender, EventArgs e)
{
string fullname = "C:\\QQ.exe";
if(File.Exists(fullname))
{
}
else//如果不存在则查找
{
FolderBrowserDialog fbd=new FolderBrowserDialog();
fbd.ShowDialog(); string RootPath = fbd.SelectedPath;
if(Directory.Exists(RootPath))
{
DirectoryInfo d = new DirectoryInfo(RootPath);
try
{
FileInfo[] FileList = d.GetFiles("QQ.exe", SearchOption.AllDirectories);
if (FileList.Length > 0)
{
fullname = FileList[0].FullName;
MessageBox.Show("QQ.exe的FullName为" + fullname);
}
else
{
MessageBox.Show("不存在此文件");
}
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show("请确保您具有足够的特权来访问此资源");
}
finally
{
this.Close();
}
}
}
}