3

I have used two GUIDs to open the folders My Computer and My Documents.

Process.Start("iexplore.exe", "::{20d04fe0-3aea-1069-a2d8-08002b30309d}");
Process.Start("iexplore.exe", "::{450d8fba-ad25-11d0-98a8-0800361b1103}");

But it opens Internet Explorer and then opens the folders My Computer and My Documents.

4

9 回答 9

40

Using those hard coded Guid values doesn't look like the best way of achieving this.

You could use the Environment.GetFolderPath function to get the path of any of the system special folders. It accepts an Environment.SpecialFolder enum.

This way it'd be more robust, because you wouldn't have any "magic" hardcoded values.

Here's how you'd use it:

//get the folder paths
string myComputerPath = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
//open explorer and point it at the paths
System.Diagnostics.Process.Start("explorer", myComputerPath);
System.Diagnostics.Process.Start("explorer", myDocumentsPath);

Important note for Windows 7 users

It seems that trying to use this code to open My Computer on Windows 7 incorrectly results in the Libraries folder being opened instead. This is because the default behaviour of running explorer with an empty path has changed in Windows 7.

I've filed the following bug report over at connect, go and give it an upvote if you think that this is important!

https://connect.microsoft.com/VisualStudio/feedback/details/757291/environment-getfolderpath-not-working-correctly-in-windows-7#details

(Thanks to JeremyK in the comments for pointing this out)

于 2009-07-02T12:29:35.410 回答
9

Have you tried:

Process.Start("explorer.exe", "::{20d04fe0-3aea-1069-a2d8-08002b30309d}");
Process.Start("explorer.exe", "::{450d8fba-ad25-11d0-98a8-0800361b1103}");

?

于 2009-07-02T12:12:31.437 回答
6

Try explorer.exe:

Process.Start("explorer.exe", "::{20d04fe0-3aea-1069-a2d8-08002b30309d}");
Process.Start("explorer.exe", "::{450d8fba-ad25-11d0-98a8-0800361b1103}");
于 2009-07-02T12:11:54.527 回答
5

Better still would be to skip explorer entirely and just "start" the GUIDs directly:

Process.Start("::{20d04fe0-3aea-1069-a2d8-08002b30309d}");...

于 2009-07-02T13:39:33.630 回答
1

This does not work for my Vista:

string myComputerPath = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
System.Diagnostics.Process.Start("explorer", myComputerPath);

as Environment.SpecialFolder.MyComputer returns "" and Process.Start("explorer", "") opens My Documents.

The GUID seems to do it, though:

Process.Start("explorer.exe", "::{20d04fe0-3aea-1069-a2d8-08002b30309d}");
于 2009-12-23T10:31:56.677 回答
1
System.Diagnostics.Process.Start("...");

I know it looks doubtful but just run it. It'll work. This is the code for my computer. I don't know what it should be for My Documents.

于 2011-04-03T03:58:43.440 回答
0

System.Diagnostics.Process.Start("...");

I know it looks doubtful but just run it. It'll work. This is the code for my computer. I don't know what it should be for My Documents.

On Windows 7 this results in opening the folder from where your executable is running, i.e. the "current" folder.

于 2013-02-01T11:24:39.157 回答
0

I had to open MyDocuments and based on comments above I narrowed down the solution to open Explorer without side effects:

Process.Start("::{450d8fba-ad25-11d0-98a8-0800361b1103}");

I tested it on Windows Server 2008 R2.

于 2014-05-02T18:54:40.427 回答
-2

Samdoss

Just enter the

System.Diagnostics.Process.Start(directoryPath);

Its very easy. Try that.

于 2011-01-20T14:52:22.120 回答