Sign in to follow this  
Followers 0
Unc3nZureD

_FileListToArray - return REAL Path

15 posts in this topic

I've been trying to make a "control" for displaying files, but it's not important currently. Let me show my problem.

​Try to _FileListToArray() your @HomeDrive.
​Probably you will see Documents and Settings folder.
​Now Try to _FileListArray that one too!
​At me it looks the following way:

#include <File.au3>
#include <Array.au3>

$a = _FileListToArray("C:\Documents and Settings")
_ArrayDisplay($a)

​It fails, since it can't detect that path. Why? Because the real dir is: "C:UsersUnknown UserDocuments"

​Any idea how to bypass this? (Not only the documents folder, but generally)

Share this post


Link to post
Share on other sites



Actually C:Documents and Settings would be the same folder as C:Users and what you're seeing is a junction point and not a real folder name. To detect whether a listed folder is actually a junction point, you can use this code.

#include <WinAPIFiles.au3>
BitAND(_WinAPI_GetFileAttributes ("C:\Documents and Settings\"), $FILE_ATTRIBUTE_REPARSE_POINT) <> 0

This returns True if the Reparse_Point attribute is set, and false if it's not. 

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

 Apparently this is a risk of some sort but i just break things, not fix them.

The following changes your permissions on the 'documents and settings' folder if ran elevated, immediately.  please make note of your own permissions PRIOR to running this script, so you can put them back if you would like to do so.

#include <File.au3>
#include <Array.au3>

runwait('cmd /c echo y | cacls "c:\Documents and Settings" /L /G Everyone:C')

$a = _FileListToArray(@HomeDrive)
_ArrayDisplay($a)

        $b = _FileListToArray("C:\Documents and Settings")
        _ArrayDisplay($b)
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

 

 Apparently this is a risk of some sort but i just break things, not fix them.

The following changes your permissions on the 'documents and settings' folder if ran elevated, immediately.  please make note of your own permissions PRIOR to running this script, so you can put them back if you would like to do so.

#include <File.au3>
#include <Array.au3>

runwait('cmd /c echo y | cacls "c:\Documents and Settings" /L /G Everyone:C')

$a = _FileListToArray(@HomeDrive)
_ArrayDisplay($a)

        $b = _FileListToArray("C:\Documents and Settings")
        _ArrayDisplay($b)

The problem is that there could be other folders with such property, so it's just a real temporary solution.

​( Anyways I didn't run the code, I just didn't want to make changes to my system :) )

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

sure but you could run through the array, returned by @homedrive, running "cacls <filename>" seeing if any of the results have the Deny Everyone permission that is set on Documents and Settings, then act on it accordingly. At its core i believe this issue is just wanting to view the contents of a directory (or link) that the user does not have rights to.  Checking to see if it's a link first doesnt seem necessary.  

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

I'm running the script as #RequireAdmin, so theritically I should have access to any folder.

Share this post


Link to post
Share on other sites

i would think not in this case, even with UAC off logged in as administrator you cannot run the dir command on that directory until you change the permissions.  I would even throw a takeown command above the cacls command just to make sure it worked.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

On Vista+ C:Documents and Settings restricts read access to deny everyone, so without hacking the file system permissions you can't traverse the link.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Okay, I understand, but maybe, is it possible to retrieve the "real" folders, not theese? I mean the way I can see it in the simple win explorer. The users folder etc.

Share this post


Link to post
Share on other sites

#include <File.au3>

Local $aJunction
Local $output = @ScriptDir & "\Junction.txt"

Local $foo = Runwait(@ComSpec & ' /c dir /AL" > ' & $output , "C:\")

_FileReadToArray($output, $aJunction)
$aSplit = stringsplit($aJunction[1] , "  " , 1)
$aBoth = stringsplit($aSplit[$aSplit[0]] , "[")
msgbox (0, '' , $aBoth[1] & " = " & stringtrimright($aBoth[2] , 1))

Something like this?  I only had a documents and settings pointer but this could easily be adapted to work with multiple matches in the array.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Or you could use the one liner I posted up above to tell you if the folder is a junction point,reparse point etc. A simple If then comparison could then be done to tell you this information.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

...or, to read the targets of any type of reparse-point properly (Junctions, Symlinks, Mountpoints), without worrying about ACL permissions or requireadmin or cmd shells, just use the _GetReparseTarget() UDF. :bye:

Share this post


Link to post
Share on other sites

I somehow missed that UDF, good work.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

My one-and-only "vaguely useful" contribution to the community.  It's rather amusing that the Windows API allows any stoned teenager with a poor taste in music to create reparse-points with his eyes closed (_WinAPI_CreateSymbolicLink), but to actually read the target of one requires a bit more thought.

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
Sign in to follow this  
Followers 0