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
Network folder exists [SOLVED]
- captain_skank
- Enthusiast
- Posts: 636
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
Network folder exists [SOLVED]
Last edited by captain_skank on Fri Apr 23, 2021 9:39 am, edited 1 time in total.
Re: Network folder exists
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
- captain_skank
- Enthusiast
- Posts: 636
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
Re: Network folder exists
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.
Re: Network folder exists
Hi captain_skank,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.
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\
Re: Network folder exists
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
And CredUIPromptForWindowsCredentials API
But it is probably simpler as indicated by Marc56
- captain_skank
- Enthusiast
- Posts: 636
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
Re: Network folder exists
Many thanks guys, Marc56us's suggestion worked a treat.
Sample code below for completeness
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")
Re: Network folder exists [SOLVED]
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:
Otherwise PROC_folder_access() return allways true on my system..
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
"Daddy, I'll run faster, then it is not so far..."