CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2002
    Location
    Philadelphia
    Posts
    150

    Shell Windows Explorer to Specific Folder

    Please help. I am trying to open Windows Explorer to specifically browse the Tasks folder from my program. Unfortunately Windows Explorer keeps opening to the "My Documents" folder.
    Code:
    // Locals
    BOOL br=FALSE;
    UINT cb=0;
    TCHAR tszWinDir[MAX_PATH];
    tszWinDir[0]=0;
    
    STARTUPINFO         siStartupInfo;
    memset(&siStartupInfo, 0, sizeof(siStartupInfo));
    
    PROCESS_INFORMATION piProcessInfo;
    memset(&piProcessInfo, 0, sizeof(piProcessInfo));
    
    CString strAppPath;
    strAppPath = _T("C:\\Winnt"); // default
    
    CString strTasksPath;
    strTasksPath = _T("C:\\Winnt"); // default
    
    // Shell Explorer to the task folder
    cb = GetWindowsDirectory(tszWinDir, MAX_PATH);
    if(cb>0)
    {
    	strAppPath = tszWinDir;
    	strTasksPath = tszWinDir;
    }
    strAppPath += _T("\\explorer.exe");
    strTasksPath += _T("\\Tasks");
    
    siStartupInfo.cb = sizeof(siStartupInfo);
    
    br = CreateProcess(strAppPath,     // Application name
    	const_cast<TCHAR*>((const TCHAR*)strTasksPath), // Application arguments
    	0,
    	0,
    	FALSE,
    	CREATE_DEFAULT_ERROR_MODE,
    	0,
    	const_cast<TCHAR*>((const TCHAR*)strTasksPath),                              // Working directory
    	&siStartupInfo,
    	&piProcessInfo);
    Sincerely,
    - Ron

  2. #2
    Join Date
    Mar 2002
    Location
    Philadelphia
    Posts
    150
    Well, when I replace the call to create process with the following it works, but I don't know why.
    Code:
    HINSTANCE hInst = ShellExecute(0,                           
                                   "open",                      // Operation to perform
                                   strAppPath,  // Application name
                                   strTasksPath,           // Additional parameters
                                   0,                           // Default directory
                                   SW_SHOW);
    Sincerely,
    - Ron

  3. #3
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917
    Code:
    	STARTUPINFO         siStartupInfo;
    	memset(&siStartupInfo, 0, sizeof(siStartupInfo));
    	
    	PROCESS_INFORMATION piProcessInfo;
    	memset(&piProcessInfo, 0, sizeof(piProcessInfo));
    	
    	CString strAppPath;
    
    	LPTSTR pBuf = strAppPath.GetBufferSetLength(MAX_PATH);
    	GetWindowsDirectory(pBuf, MAX_PATH);
    	strAppPath.ReleaseBuffer();
    	
    	CString strTasksPath = " /e, /root, ";
    
    	strTasksPath += strAppPath;	
    	strTasksPath += _T("\\Tasks");
    		
    	strAppPath += _T("\\explorer.exe");
    
    	siStartupInfo.cb = sizeof(siStartupInfo);
    	
    	if(!CreateProcess(strAppPath,     // Application name
    		(LPTSTR)(LPCTSTR)strTasksPath, // Application arguments
    		0,
    		0,
    		FALSE,
    		CREATE_DEFAULT_ERROR_MODE,
    		0,
    		NULL,                              // Working directory
    		&siStartupInfo,
    		&piProcessInfo))
        {
            AfxMessageBox("CreateProcess failed.");
    		DWORD dw = GetLastError();
        }
    Will open Tasks as root directory.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  4. #4
    Like this.

    Code:
    CString cmdLine = strAppPath + CString(" ") + strTasksPath;
    
    br = CreateProcess(NULL,     // Application name
    	cmdLine,	0,
    	0,
    	FALSE,
    	CREATE_DEFAULT_ERROR_MODE,
    	0,
    	const_cast<TCHAR*>((const TCHAR*)strTasksPath),                              // Working directory
    	&siStartupInfo,
    	&piProcessInfo);
    Best Api Monitor tool.
    Trace the target program automatically and monitor the parameters of all API and COM interfaces.

    Auto Debug for Windows 4.0
    Auto Debug for .Net
    http://www.autodebug.com/

  5. #5
    Join Date
    Mar 2002
    Location
    Philadelphia
    Posts
    150
    That is too wierd. Twas the extra space that did it.
    Thank you both for your replies.
    Sincerely,
    - Ron

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured