Fastest way to get file/dir access rights?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Taurus
Posts: 94
Joined: 20 Jan 2015, 10:31

Fastest way to get file/dir access rights?

22 Mar 2018, 05:22

Hi,

I created a function which checks for file/dir access rights. Locally it is very fast. Over network it's consuming ~ 1 sec. Is there any faster way to get them? Maybe with a FileObject?

Restriction: it has to work on network drives of Win, Win Server, NAS and Linux-Server and should be error proof.

Here is my code:

Code: Select all

Check_Rights(ByRef Dir)
{
	if(InStr( FileExist(Dir), "D" )=0)
		return "dir not exist"		
	
	Random, tmp, 0, 99
	
	File_Write_Test := Dir "\" A_UserName A_TickCount tmp ".ini"
	
	Loop, 50
	{	
		FileAppend, 0, % File_Write_Test		
		if(ErrorLevel)
		{
			if(A_Index = 50)
				return "no write"
			else
				Sleep, 100		
		}
		else
			break
	}
	
	Loop, 50
	{	
		FileAppend, 0, % File_Write_Test		
		if(ErrorLevel)
		{
			if(A_Index = 50)
				return "no change"
			else
				Sleep, 100		
		}
		else
			break
	}
	
	Loop, 50
	{
		FileDelete, % File_Write_Test "*"
		if(ErrorLevel)
		{
			if(A_Index = 50)
				return "no delete"
			else
				Sleep, 100		
		}
		else
			break
	}
	
	return "ok"
}
Thx! :)
:beard: Full Stack Developer > Dev for a better world | PHP for Web | AHK H for Local | with KISS (Keep IT Short and Simple) on Win 10 Pro (Version 2004) x64
Guest

Re: Fastest way to get file/dir access rights?

22 Mar 2018, 09:45

Find somebody willing to convert http://blog.aaronballman.com/2011/08/ho ... ss-rights/ (taking in remarks from the comments below) into AHK DllCalls.

But honestly, with three loops possibly running many Sleep 100s it's not surprising to hear this function can be slow. You might be able to speed it up by seeing if A_LastError was 5 (ERROR_ACCESS_DENIED) or something and breaking.
User avatar
Taurus
Posts: 94
Joined: 20 Jan 2015, 10:31

Re: Fastest way to get file/dir access rights?

22 Mar 2018, 14:28

You are right, i improved it: :)
if(A_LastError = 3) ; ERROR_PATH_NOT_FOUND
return "ERROR_PATH_NOT_FOUND"
else if(A_LastError = 5 || A_Index = 50) ; ERROR_ACCESS_DENIED
return "ERROR_ACCESS_DENIED"
else
Sleep, 100
Now i need to get the double loop removed, but i don't know, how to check for modify right without it.

At the moment, i am not able to read that dll-calls. Maybe in future. :cry:
:beard: Full Stack Developer > Dev for a better world | PHP for Web | AHK H for Local | with KISS (Keep IT Short and Simple) on Win 10 Pro (Version 2004) x64

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, onurcoban and 364 guests