Network folder exists [SOLVED]

Just starting out? Need help? Post your questions and find answers here.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Network folder exists [SOLVED]

Post by captain_skank »

Hi,

I need to check if a directory exist's on a fileserver ( windows/samba ) E.G \\SERVER\FOLDER\

I tried using examinedirectory() and that works as expected, but if the user does not have access to the directory, windows pops up the credentail entry window.

So, how can this be done without the credentials window appearing ?

Any help/advice appreciated.

Cheers
Last edited by captain_skank on Fri Apr 23, 2021 9:39 am, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Network folder exists

Post by mk-soft »

Bind a local drive "Z" to network path with save user and password.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: Network folder exists

Post by captain_skank »

Thanks for the reply, but I specifically want to know if the user does not have permision and to report that back without the credentials alert popping up.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Network folder exists

Post by Marc56us »

captain_skank wrote: Thu Apr 22, 2021 4:13 pm I need to check if a directory exist's on a fileserver ( windows/samba ) E.G \\SERVER\FOLDER\
...
Thanks for the reply, but I specifically want to know if the user does not have permision and to report that back without the credentials alert popping up.
Hi captain_skank,

There is probably an API, but in the meantime you can use the ICACLS command line utility (with runprogram())
(not tested)
Edit: Tested ICACLS returns the rights only if it can read them, so log in.

Otherwise, same with commandline

Code: Select all

NET VIEW \\SERVER\FOLDER\
Return Error 5 if acces deny

:wink:
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Network folder exists

Post by ChrisR »

You can take a look at Windows.UI.CredDialogController.dll file that prompts user credential.

And CredUIPromptForWindowsCredentials API

But it is probably simpler as indicated by Marc56
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 636
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: Network folder exists

Post by captain_skank »

Many thanks guys, Marc56us's suggestion worked a treat.

Sample code below for completeness

Code: Select all

Declare.i PROC_folder_access(PVAR_folder.s)

Procedure.i PROC_folder_access(PVAR_folder.s)
  
  ; Procedure returns #True if user has permission to access the folder
  ; or #False if not
  
  LVAR_return.i
  LVAR_program.i = RunProgram("ICACLS", PVAR_folder, "", #PB_Program_Open | #PB_Program_Read)
  LVAR_output.s = ""

  While ProgramRunning(LVAR_program)
    If AvailableProgramOutput(LVAR_program)
      LVAR_output + ReadProgramString(LVAR_program) + Chr(13)
    EndIf
  Wend
  
  If ProgramExitCode(LVAR_program) = 5
    ;Debug "No permission for " + PVAR_folder
    LVAR_return = #False
  Else
    ;Debug "You have permission to access " + PVAR_folder
    LVAR_return = #True
  EndIf
  
  ; Close the connection to the program
  CloseProgram(LVAR_program) 
    
  ProcedureReturn LVAR_return
  
EndProcedure

Debug PROC_folder_access("\\SERVER_NAME\FOLDER_NAME")
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Network folder exists [SOLVED]

Post by dige »

I'm not sure, if the program exit code is the right way. I guess its better to check the program output or the success exit code should null like:

Code: Select all

If ProgramExitCode(LVAR_program) <> 0
    ;Debug "No permission for " + PVAR_folder
    LVAR_return = #False
  Else
    ;Debug "You have permission to access " + PVAR_folder
    LVAR_return = #True
  EndIf
Otherwise PROC_folder_access() return allways true on my system..
"Daddy, I'll run faster, then it is not so far..."
Post Reply