加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

资源管理器explorer.exe参数说明-打开指定文件夹并选择文件

(2012-02-18 10:58:02)
标签:

explorer

聚焦文件

杂谈

概要
本分步指南介绍了如何在 Windows XP 中使用 Windows 资源管理器命令行参数。



更多信息
使用命令行参数,您既可以自定义 Windows 资源管理器启动时使用的默认视图,也可以指定在从命令提示符启动时所看到的视图。

您可以在 Explorer.exe 命令中使用以下参数。

参数 结果
/n   为默认选择内容打开一个新的单窗格窗口。
默认选择内容通常是安装 Windows 的驱动器的根目录。
/e 使用默认视图启动 Windows 资源管理器。
/e, <object> 使用默认视图启动 Windows 资源管理器并把焦点定位在指定文件夹上。
/root, <object> 打开指定对象的一个窗口视图。
/select, <object> 打开一个窗口视图,指定的文件夹、文件或
程序被选中。




从命令提示符下运行 Windows 资源管理器
若要从命令提示符下运行 Windows 资源管理器,请: 1. 单击开始,然后单击运行。
2. 在打开框中,键入 Explorer,然后单击确定。

示例
以下示例说明了 Windows 资源管理器参数的用法。 • Explorer /n
此命令使用默认设置打开一个资源管理器窗口。显示的内容通常是安装 Windows 的驱动器的根目录。
• Explorer /e
此命令使用默认视图启动 Windows 资源管理器。
• Explorer /e,C:\Windows
此命令使用默认视图启动 Windows 资源管理器,并把焦点定位在 C:\Windows。
• Explorer /root, C:\Windows\Cursors
此命令启动 Windows 资源管理器后焦点定位在 C:\Windows\Cursors folder。此示例使用 C:\Windows\Cursors 作为 Windows 资源管理器的“根”目录。

备注:请注意命令中“/root”参数后面的逗号。
• Explorer /select, C:\Windows\Cursors\banana.ani
此命令启动 Windows 资源管理器后选定“C:\Windows\Cursors\banana.ani”文件。

备注£º请注意命令中“/select”参数后面的逗号。
Windows 资源管理器参数可以在一个命令中进行组合。以下示例显示了 Windows 资源管理器命令行参数的组合。 • Explorer /root, \\server\share, select, Program.exe
此命令启动 Windows 资源管理器时以远程共享作为“根”文件夹,而且 Program.exe 文件将被选中。



更改 Windows 资源管理器默认启动文件夹
若要更改 Windows 资源管理器的默认启动文件夹,请: 1. 单击开始,指向所有程序,指向附件,然后右键单击Windows Explorer。
2. 在出现的菜单上,单击属性。
3. 在“目标”框中,将“/root”命令行参数附加到“%SystemRoot%\Explorer.exe”命令之后,并使用您希望的启动位置。例如,如果您希望 Windows 资源管理器启动后定位在 C 驱动器的根,则请将该命令编辑为:
%SystemRoot%\Explorer.exe /root, C:\
4. 单击确定。


 

//打开文件所在的文件夹,并选择文件

void OpenFolderAndSelect( const CString& strFile)
{
 CString strDest(_T("/n,/select, "));
 strDest += strFile;
 SHELLEXECUTEINFO se;
 ZeroMemory(&se, sizeof(se));
 se.cbSize = sizeof(se);
 se.fMask = SEE_MASK_NOCLOSEPROCESS;
 se.hwnd = NULL;
 se.lpVerb = NULL;
 se.lpFile = _T("explorer.exe");
 se.lpParameters = strDest;
 se.lpDirectory = _T("");
 se.nShow = SW_SHOWNORMAL;
 se.hInstApp = NULL;
 ShellExecuteEx(&se);
}

 

方法二:

BOOL OpenFolderAndSelectFile( LPSTR lpszFilePath)
{
    
//
    // GetFolder
    //
    DWORD dw = lstrlenA(lpszFilePath) - 1;
    for (;dw != -1;dw--)
     {
        if ( lpszFilePath[dw] == '\\')
         {
            break;
         }
     }
    if ( dw == -1)
     {
        return
FALSE;
     }
    //
    // Get a pointer to the Desktop's IShellFolder interface.
    //
     LPSHELLFOLDER pDesktopFolder;
    if ( SUCCEEDED(SHGetDesktopFolder( &pDesktopFolder)))
     {
        //
        // IShellFolder::ParseDisplayName requires the file name be in
        // Unicode.
        //
         OLECHAR oleStr[MAX_PATH];

         lpszFilePath[dw] = '\0';
         MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
             lpszFilePath, -1, oleStr, _countof(oleStr));
        //
        // Convert the path to an ITEMIDLIST.
        //
         LPITEMIDLIST     pidl;
        ULONG             chEaten;
        ULONG             dwAttributes;
        HRESULT             hr;

         hr = pDesktopFolder->ParseDisplayName(
             NULL, NULL, oleStr, &chEaten, &pidl, &dwAttributes);
        if (FAILED(hr))
         {
             pDesktopFolder->Release();
            return FALSE;
         }
         LPCITEMIDLIST pidlFolder = pidl;

         lpszFilePath[dw] = '\\';
         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
             lpszFilePath, -1, oleStr, _countof(oleStr));

         hr = pDesktopFolder->ParseDisplayName(
             NULL, NULL, oleStr, &chEaten, &pidl, &dwAttributes);
        if (FAILED(hr))
         {
             pDesktopFolder->Release();
            return FALSE;
         }
         LPCITEMIDLIST pidlFile = pidl;

         CoInitialize( NULL);
         hr = SHOpenFolderAndSelectItems( pidlFolder, 1, &pidlFile, 0);

         pDesktopFolder->Release();

        if ( hr == S_OK)
         {
            return TRUE;
         }
     }
    return FALSE;
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有