様々な方法でエクスプローラを開く

注意:
この文書は以前「.NETでいきまっしょい!」で公開していたものですが、公開以降メンテナンスされていません。 今や古い情報となった内容が記載されている場合があるのでご注意ください。

 explorer.exeを起動する際に引数を指定することで、様々な方法で起動することができる。 引数には次のようなものがある。 また、特殊なフォルダを開くこともできる。
/nフォルダツリーを付けずに表示する
/eフォルダツリーを付けてに表示する
/root,[パス]指定されたパスをルートとして表示する。 指定されたパスより上のフォルダを表示することはできない。
/select,[パス]パスで指定されたファイル・フォルダが選択された状態で表示する。
VB.NET
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
Imports System
Imports System.Diagnostics

Module MainModule

    Sub Main()

        ' ツリーなし
        Process.Start("explorer.exe", "/n,C:\")
        ' ツリー付き
        Process.Start("explorer.exe", "/e,C:\")

        ' ツリー付きルート指定
        Process.Start("explorer.exe", "/e,/root,C:\Windows")
        ' C:\を開いてC:\Windowsを選択
        Process.Start("explorer.exe", "/n,/select,C:\Windows")
        ' C:\Windows\を開いてC:\Windows\Explorer.exeを選択
        Process.Start("explorer.exe", "/n,/select,C:\Windows\Explorer.exe")

        ' マイコンピュータを開く
        Process.Start("explorer.exe", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
        ' ゴミ箱を開く
        Process.Start("explorer.exe", "::{645FF040-5081-101B-9F08-00AA002F954E}")
        ' マイドキュメントを開く
        Process.Start("explorer.exe", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}")

        ' マイドキュメントを開く(別の方法)
        Process.Start( "explorer.exe", Environment.GetFolderPath( Environment.SpecialFolder.Personal ) )

    End Sub

End Module
C#
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
using System;
using System.Diagnostics;

namespace Sample
{
    class Sample
    {
        public static void Main()
        {
            // ツリーなし
            Process.Start( "explorer.exe", "/n,C:\\" );
            // ツリー付き
            Process.Start( "explorer.exe", "/e,C:\\" );

            // ツリー付きルート指定
            Process.Start( "explorer.exe", "/e,/root,C:\\Windows" );
            // C:\を開いてC:\Windowsを選択
            Process.Start( "explorer.exe", "/n,/select,C:\\Windows" );
            // C:\Windows\を開いてC:\Windows\Explorer.exeを選択
            Process.Start( "explorer.exe", "/n,/select,C:\\Windows\\Explorer.exe" );

            // マイコンピュータを開く
            Process.Start( "explorer.exe", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" );
            // ゴミ箱を開く
            Process.Start( "explorer.exe", "::{645FF040-5081-101B-9F08-00AA002F954E}" );
            // マイドキュメントを開く
            Process.Start( "explorer.exe", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}" );

            // マイドキュメントを開く(別の方法)
            Process.Start( "explorer.exe", Environment.GetFolderPath( Environment.SpecialFolder.Personal ) );
        }
    }
}