Thread: Programmatically open a Windows Folder

  1. #1
    Registered User
    Join Date
    Sep 2001

    Question Programmatically open a Windows Folder

    I am looking for a way to open a windows folder from within my programme as if it had been opened from within 'MyComputer'
    I guess it is an API command but have looked in all my documentation and found nothing. I am programming in Borland C++ for Windows 95/98 OS. Any help would very appreciated.


  2. #2
    I found this in my Windows API documentation. I never used this function, so I don't know whether it works. Maybe it's obselete, for win16 or something. Try it. Here is the description I found:
    #include ver.h

    UINT GetWindowsDir(lpszAppDir, lpszPath, cbPath)

    LPCSTR lpszAppDir; /* address of Windows directory */
    LPSTR lpszPath; /* address of buffer for path */
    int cbPath; /* size of buffer for path */

    The GetWindowsDir function retrieves the path of the Windows directory. This directory contains such files as Windows applications, initialization files, and help files.
    GetWindowsDir is used by MS-DOS applications that set up Windows applications; it exists only in the static-link version of the File Installation library. Windows applications should use the GetWindowsDirectory function to determine the Windows directory.

    Parameter Description

    lpszAppDir Specifies the current directory in a search for Windows files. If the Windows directory is not on the path, the application must prompt the user for its location and pass that string to the GetWindowsDir function in the lpszAppDir parameter.
    lpszPath Points to the buffer that will receive the null-terminated string containing the path.
    cbPath Specifies the size, in bytes, of the buffer pointed to by the lpszPath parameter.


    The return value is the length of the string copied to the lpszPath parameter, including the terminating null character, if the function is successful. If the return value is greater than the cbPath parameter, it is the size of the buffer required to hold the path. The return value is zero if the function fails.


    The path that this function retrieves does not end with a backslash unless the Windows directory is the root directory. For example, if the Windows directory is named WINDOWS on drive C, the path retrieved by this function is C:\WINDOWS. If Windows is installed in the root directory of drive C, the path retrieved is C:\.

    After the GetWindowsDir function locates the Windows directory, it caches the location for use by subsequent calls to the function.

  3. #3
    Oh... Sorry, I see you asked for something else. Well, what about calling an explorer.exe application from the directory you get as a result of getWindowsDir function? Just run it as "windowsdirectory\explorer.exe windowsdirectory" It creates an explorer.exe window with this directory opened (without the tree, exactly as if it would from My Computer icon (if you use w98)).

  4. #4
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    You could use ShellExecute(). This would open c:\Temp -

    ShellExecute(hWnd,"open",NULL,NULL,"C:\\Temp",SW_S HOWNORMAL);

    If you need an explorer type view you can change the "open" to "explore".

  5. #5
    Registered User
    Join Date
    Sep 2001

    Thumbs up Thanx Guys

    Thanx for your help, never even thought of using ShellExecute


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Who doesn't format Windows?
    By C_ntua in forum Tech Board
    Replies: 89
    Last Post: 11-11-2008, 12:29 PM
  2. Codec Bitrates?
    By gvector1 in forum C# Programming
    Replies: 2
    Last Post: 06-16-2003, 08:39 AM
  3. FlashWindowEx not declared?
    By Aidman in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 02:58 AM
  4. Problems with open and save boxes
    By pinkcheese in forum Windows Programming
    Replies: 3
    Last Post: 05-21-2002, 06:03 PM
  5. open folder
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 05-10-2002, 12:36 AM