Jump to content

Run/ShellExecute windows folder locations

Recommended Posts



What command would I use to open the following folder directories for:

Computer/This PC (windows 7/Windows 10)



I know:

 Run("Explorer.exe " & $filepath)

can be used to open folder locations when you type in the full directory such as "C:\Users\%username%\Documents" but I'm trying to figure out how to use these windows short paths. 


Share this post

Link to post
Share on other sites
21 hours ago, Subz said:

Sorry pushed submit by accident, I meant to say

Do you mean macros like @DocumentsDir or did you want special folders like:



Referring to things like @DocumentsDir (Which gives me an error of undefined macro. Guessing I'm missing an #include?)


See right now, before a user is allowed to save an address I use:


to check if the path exists, but in this case if $inputaddress was to be "Libraries\Pictures" this would return 0 (Path/file does not exist). However if I go into windows explore and type "Libraries\Pictures" (or just "Pictures" for that matter) it takes me to C:\Users\(username)\Pictures and will not display the full path it just shows "Libraries\Documents".

So I'm trying to find out if there is a way that if the user enters in one of these shorten versions of the file path such as "Libraries\Pictures" the code will be able to recognize this as a true path and will be able to open that file location.

With further testing I've discovered that both:

Run('Explorer.exe ' & "Libraries\Pictures")

Don't work either, so I'm starting to think this might be a complicated thing to do for me....

Share this post

Link to post
Share on other sites

Sorry, @DocumentsDir should have been - @MyDocumentsDir

Libraries are ultimately shortcut files with the extension .library-ms files and can be located in @AppDataDir & '\Microsoft\Windows\Libraries.

You can use something like the following and it will open to that location

ShellExecute('Explorer.exe', @AppDataDir & '\Microsoft\Windows\Libraries\Pictures.library-Ms')

The file itself is actually xml, if you use a parser you can grab the <simplelocation>><url>knownfolder:{Guid} you can view a list of Guids and there locations here:


Share this post

Link to post
Share on other sites

I created a function to do something similar a while ago. You may be able to adapt for your needs.

#include <WinAPIShellEx.au3>
#include <WinAPI.au3>

Local $s_FilePath = _Win7_GetKnownFolder('PicturesLibrary')

if @error Then
    MsgBox(0,'DOH!', $s_FilePath)
    MsgBox(0,'Yay Found', 'Path: '& $s_FilePath & @crlf & 'File Exists: ' & FileExists($s_FilePath))

; #FUNCTION# ====================================================================================================================
; Name ..........: _Win7_GetKnownFolder
; Description ...: Retrieves the full path of a known folder
; Syntax ........: _Win7_GetKnownFolder($s_Folder)
; Parameters ....: $s_Folder  - A string value denoting the known folder
; Return values .: Success - Returns the full folder path
;                  Failure - Sets @error to 1 and returns a string for logging
; Remarks .......: Only for Windows Vista and above
; Related .......: _XP_GetSpecialFolder (for XP and lower)
; Link ..........: link http://msdn.microsoft.com/en-us/library/dd378457.aspx
; Example .......: _Win7_GetKnownFolder('CommonPrograms')
; ===============================================================================================================================
Func _Win7_GetKnownFolder($s_Folder)
    ; trimmed list of KnownFolder constants
    Local $s_Constants = 'CommonPrograms|' & _ ;%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs
            'CommonStartMenu|' & _ ; %ALLUSERSPROFILE%\Microsoft\Windows\Start Menu
            'CommonStartup|' & _ ; %ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\StartUp
            'CommonTemplates|' & _ ; %ALLUSERSPROFILE%\Microsoft\Windows\Templates
            'Desktop|' & _ ; %USERPROFILE%\Desktop
            'Documents|' & _ ; %USERPROFILE%\Documents
            'DocumentsLibrary|' & _ ; %APPDATA%\Microsoft\Windows\Libraries\Documents.library-ms
            'Favorites|' & _ ; %USERPROFILE%\Favorites
            'Fonts|' & _ ; %windir%\Fonts
            'Libraries|' & _ ; %APPDATA%\Microsoft\Windows\Libraries
            'LocalAppData|' & _ ; %LOCALAPPDATA% (%USERPROFILE%\AppData\Local)
            'LocalAppDataLow|' & _ ; %USERPROFILE%\AppData\LocalLow
            'Music|' & _ ; %USERPROFILE%\Music
            'MusicLibrary|' & _ ; %APPDATA%\Microsoft\Windows\Libraries\Music.library-ms
            'PhotoAlbums|' & _ ; %USERPROFILE%\Pictures\Slide Shows
            'PicturesLibrary|' & _ ; %APPDATA%\Microsoft\Windows\Libraries\Pictures.library-ms
            'Pictures|' & _ ; %USERPROFILE%\Pictures
            'Playlists|' & _ ; %USERPROFILE%\Music\Playlists
            'Profile|' & _ ; %USERPROFILE% (%SystemDrive%\Users\%USERNAME%)
            'ProgramData|' & _ ; %ALLUSERSPROFILE% (%ProgramData%, %SystemDrive%\ProgramData)
            'ProgramFiles|' & _ ; %ProgramFiles% (%SystemDrive%\Program Files)
            'ProgramFilesX64|' & _ ; %ProgramFiles% (%SystemDrive%\Program Files)
            'ProgramFilesX86|' & _ ; %ProgramFiles% (%SystemDrive%\Program Files)
            'ProgramFilesCommon|' & _ ; %ProgramFiles%\Common Files
            'ProgramFilesCommonX64|' & _ ; %ProgramFiles%\Common Files
            'ProgramFilesCommonX86|' & _ ; %ProgramFiles%\Common Files
            'Programs|' & _ ; %APPDATA%\Microsoft\Windows\Start Menu\Programs
            'Public|' & _ ; %PUBLIC% (%SystemDrive%\Users\Public)
            'PublicDesktop|' & _ ; %PUBLIC%\Desktop
            'PublicDocuments|' & _ ; %PUBLIC%\Documents
            'PublicLibraries|' & _ ; %ALLUSERSPROFILE%\Microsoft\Windows\Libraries
            'PublicMusic|' & _ ; %PUBLIC%\Music
            'PublicPictures|' & _ ; %PUBLIC%\Pictures
            'PublicVideos|' & _ ; %PUBLIC%\Videos
            'QuickLaunch|' & _ ; %APPDATA%\Microsoft\Internet Explorer\Quick Launch
            'ResourceDir|' & _ ; %windir%\Resources
            'RoamingAppData|' & _ ; %APPDATA% (%USERPROFILE%\AppData\Roaming)
            'SendTo|' & _ ; %APPDATA%\Microsoft\Windows\SendTo
            'StartMenu|' & _ ; %APPDATA%\Microsoft\Windows\Start Menu
            'Startup|' & _ ; %APPDATA%\Microsoft\Windows\Start Menu\Programs\StartUp
            'System|' & _ ; %windir%\system32
            'SystemX86|' & _ ; %windir%\system32
            'Templates|' & _ ; %APPDATA%\Microsoft\Windows\Templates
            'UserPinned|' & _ ; %APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned
            'UserProfiles|' & _ ; %SystemDrive%\Users
            'UserProgramFiles|' & _ ; %LOCALAPPDATA%\Programs
            'UserProgramFilesCommon|' & _ ; %LOCALAPPDATA%\Programs\Common
            'Videos|' & _ ; %USERPROFILE%\Videos
            'VideosLibrary|' & _ ; %APPDATA%\Microsoft\Windows\Libraries\Videos.library-ms
            'Windows' ; %windir%

    ; check the passed folder name is listed
    If Not _String_SearchForWords($s_Constants, $s_Folder) Then Return SetError(1, 0, '"' & $s_Folder & '" ' & ' is not listed in the Known Folder list')

    ; return the value of the variable
    Local $s_GUID = Eval('FOLDERID_' & $s_Folder)

    ; get the known folder path
    Local $s_FolderPath = _WinAPI_ShellGetKnownFolderPath($s_GUID)
    If @error Then Return SetError(@error, @extended, _WinAPI_GetLastErrorMessage())
    Return $s_FolderPath
EndFunc   ;==>_Win7_GetKnownFolder

; #FUNCTION# ====================================================================================================================
; Name ..........: _String_SearchForWords
; Description ...: Search for the existance of multiple words in a given string
; Syntax ........: _String_SearchForWords($sCallingFunc, $sTest, $sSearch)
; Parameters ....: $sTest        - The string to run the check against
;                  $sSearch      - The string(s) to search for
; Return values .: Success - Returns 0 - No Match
;                                    1 - Match
;                  Failure - Sets @error to 1 and logs an error message
; Example .......: MsgBox(0,'', _String_SearchForWords('', 'batcave1,batcave2,xbmc,benneraswell', 'batcave'))
; ===============================================================================================================================
Func _String_SearchForWords($sTest, $sSearch)
    Local $sRunningFunc = '_String_SearchForWords'
    Local $sPattern = '(?i)^(?=.*\b' & StringReplace($sSearch, '|', '\b)(?=.*\b') & '\b)'
    Local $iRet = StringRegExp($sTest, $sPattern)

    If @error Then Return SetError(@error, @extended, '')
    Return $iRet
EndFunc   ;==>_String_SearchForWords

Or probably better for you

Local $s_FileName = FileSelectFolder('Please Select The Folder...', '', 3, "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")

If Not @error Then
    ; get the folder name of any special folders
    If StringInStr($s_FileName, '::{') Then
        $s_DisplayName = SpecialFolders_GetSelfName($s_FileName)
        $s_FileName = SpecialFolder_ReturnPath($s_FileName)

    MsgBox(0,'', $s_FileName)
    ; check fileexists

Func SpecialFolder_ReturnPath($s_Path)
    Local $s_Lnk = @TempDir & '\FileName.lnk'

    ; creste a shortcut for the path
    If Not FileCreateShortcut($s_Path, $s_Lnk) Then Return $s_Path

    ; read the shortcuts property to an array
    Local $a_Shortcut = FileGetShortcut($s_Lnk)
    If @error Then Return $s_Path

    ; get the shortcut target path
    If IsArray($a_Shortcut) Then Return $a_Shortcut[0]
    Return $s_Path
EndFunc   ;==>SpecialFolder_ReturnPath

Func SpecialFolders_GetSelfName($s_Path)
    Local $objShell = ObjCreate("Shell.Application")
    If Not IsObj($objShell) Then Return ''

    Return $objShell.NameSpace($s_Path).Self.Name
EndFunc   ;==>SpecialFolders_GetSelfName


Edited by benners
  • Like 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • rkr
      By rkr
      Hi, I have a software which has a 'run file'-ie; when i double click on that file, the input file of the software is run by the software. I wish to double click/execute this run file using autoit. how do i achieve this. i opened the software and it shows the input file and run file in same folder, i will put my autoitscript file too in same location. how do i simulate double clicking the run file (using its file name, say - abc.run ). I entered the following lines to make software window active - it became active, dont know how to go forward
      Winactivate("program title")
      winwaitactivate("program title")
      controlclick("program title","abc.run",1000,"primary",2) ; 1000 is ctrl id
    • tremolux66
      By tremolux66
      Initial Problem
      I've written several scripts with the following sequence:
      Execute a program using Run w/stdout+stderr captured Typically processes all the files in one directory tree to populate a second tree Execute a second program (also with Run) to monitor the products of the first program and Display a progress bar (percentage of output files complete) Also monitor the first program's process and exit when it terminates The script then calls ProcessWaitClose (no timeout) on the first program's process and Checks the first program's results Kills the monitor program if it hasn't already exited on its own. Sometimes, ProcessWaitClose returns 1 with @error = 0 and @extended = 0xCCCCCCCC (actually, 0xFFFFFFFFCCCCCCCC), which seems ambiguous: the documentation says that @error = non-zero and @extended = 0xCC... means an invalid PID (unclear what the return value is), and 1 is returned for non-existent processes (but no mention of @extended). The 1/0/0xCC... result seems to occur when the first program exits very quickly (with or without an error). Since the exit value is not available, the script scans the program's output and tries to determine whether it ran successfully. This has gotten complicated and unreliable.
      Partial Fix
      I've now implemented a much simpler approach that works for most cases:
      Modify the monitor program so that it ignores the other program's process (the monitor always gets killed by the script anyway) Execute the monitor program first using Run, then execute the processing program with RunWait When RunWait returns, the child process exit value is available, so the script can ignore its output (which isn't available anyway) If the monitor program is still running, kill it. Remaining Issue
      However, there are still a couple of cases where it's necessary to get both the exit value from the processing program and its output. Since RunWait doesn't capture stdout and stderr for the parent script, it's looking like I'll have to call RunWait and redirect the 2 streams to a temp file and then scan it. Also, to do the redirect, I think I'll have to use @ComSpec to execute the processing program, which adds an undesired layer.
      Does anybody have a better (cleaner) way to handle these cases?
    • e45678mail
      By e45678mail
      I have some question about how to enable the test mode via "Run" or "shellexecute" of command,
      was to tried :
      Run("bcdedit.exe /-set testsinging on", "C:\Windows\System32")
      shellexecute("bcdedit.exe /-set testsinging on", "C:\Windows\System32")
      since this command must to run through administrator competence,
      have any method can accomplish it?
    • BlazerV60
      By BlazerV60
      Hello all,
      I've written the code below which launches chrome in incognito mode and then proceeds to go to the autoit website.
      From my understanding, the Run() command is also supposed to output the PID number related to the application that got launched from the Run command.
      However when I run the below lines, it outputs a PID number that is different from the newly launched chrome browser's PID number, does anyone know why and possibly explain how I could retrieve the accurate PID number associated with the newly launched browser?
      Global $iPid = Run(@ComSpec & ' /c start chrome.exe https://www.autoitscript.com/forum/ -incognito' ,"", "") msgbox(0,"",$iPid) Thank you,

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.