我怎么可以打开的窗口资源管理器一定目录内WPF程序?
-
20-09-2019 - |
题
在WPF应用程序,当一个用户点击按钮我想要打开窗户资源管理器一定的目录,我该怎么做?
我希望事情是这样的:
Windows.OpenExplorer("c:\test");
解决方案
为什么不 Process.Start(@"c:\test");
?
其他提示
此应该工作:
Process.Start(@"<directory goes here>")
或者,如果你想运行的程序/打开的文件和/或文件夹的方法:
private void StartProcess(string path)
{
ProcessStartInfo StartInformation = new ProcessStartInfo();
StartInformation.FileName = path;
Process process = Process.Start(StartInformation);
process.EnableRaisingEvents = true;
}
和然后调用该方法,并在括号把文件的任一目录和/或文件夹中有或应用程序的名称。希望这有助于!
可以使用System.Diagnostics.Process.Start
。
或者直接用类似于以下,这将启动Explorer.exe的使用WINAPI。可以使用第四个参数的ShellExecute给它一个开始目录。
public partial class Window1 : Window
{
public Window1()
{
ShellExecute(IntPtr.Zero, "open", "explorer.exe", "", "", ShowCommands.SW_NORMAL);
InitializeComponent();
}
public enum ShowCommands : int
{
SW_HIDE = 0,
SW_SHOWNORMAL = 1,
SW_NORMAL = 1,
SW_SHOWMINIMIZED = 2,
SW_SHOWMAXIMIZED = 3,
SW_MAXIMIZE = 3,
SW_SHOWNOACTIVATE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOWMINNOACTIVE = 7,
SW_SHOWNA = 8,
SW_RESTORE = 9,
SW_SHOWDEFAULT = 10,
SW_FORCEMINIMIZE = 11,
SW_MAX = 11
}
[DllImport("shell32.dll")]
static extern IntPtr ShellExecute(
IntPtr hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
ShowCommands nShowCmd);
}
的声明来自 pinvoke.net网站。
Process.Start("explorer.exe" , @"C:\Users");
我不得不使用它,只是指定TGT目录将关闭,当我的应用程序终止浏览器窗口的其他方式。
不隶属于 StackOverflow