Solved How to programmatically pass authentication to a network folder? (1 Viewer)

ysdai

Member
Local time
Today, 03:13
Joined
Nov 28, 2019
Messages
46
Hi,

I have a table with a field named [ImgagePath] that stores pictures of items. Images are stored on a folder in the server.

I have set up the folder to be completely public but not browsable, that means anyone can access the folder if he/she types in the path \\server\folder directly in the address bar of the Windows Explorer, but it will not be visible in the network browser. I did it this way so that, presumably, my code will save the user-selected images into that folder, from any computer in the LAN without having to login, and without users knowing where the images went.

But still, Windows will pop up an authentication dialog box whenever I try to access this folder in Explorer after a restart, and as for Access, it would simply say folder not found. At the authentication window, though, I could just type in any random characters as username and the folder will open, but still Windows insists on showing that authentication box the first time a user tries to access that folder. After an authentication with any username, Access would be able to save/view the images just fine.

So, obviously I need some way to authenticate by code. Maybe I can shell net use to achieve that, but I'd probably have to map a drive on the fly and then un-map it. Doesn't sound like a good method. Is there some other way to do this?
 
Solution
Figured it out myself. Turns out the solution is so simple that I was ashamed of myself for even asking.
Just put this line in the startup script or Form_Load event of the startup form, and this resource will stay accessible until the next reboot.
Code:
Shell "net use \\server\share /user:usr pwd", vbHide
It seems net use can indeed be used just to authenticate a network share, no drive mapping is necessary.
In my case, I can type anything in place of usr and pwd, but they must both be there or else there will be a command prompt window waiting for the user to type in the values. Of course you'll need to supply a valid username and password if the share actually requires it.

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:13
Joined
May 7, 2009
Messages
19,169
is it a shared folder you are talking here?
suffix your shared folder with $ to make it appear
invisible to the naked eye.

typing \\server\folder will not open the folder, he need to type
it with a suffix $.

if this is sharing folder, there is a system setting that does not need
authentication (password) of user to access the shared folder.
 

ysdai

Member
Local time
Today, 03:13
Joined
Nov 28, 2019
Messages
46
is it a shared folder you are talking here?
suffix your shared folder with $ to make it appear
invisible to the naked eye.
It's a folder in the Ubuntu Samba server, to be exact, so I just specify browsable = no and that share will be hidden.
if this is sharing folder, there is a system setting that does not need
authentication (password) of user to access the shared folder.
If you can access that folder with any random string as username and no password, that means there is already no restriction to access. I just don't know why Windows insists on throwing out an authentication box just for you to type anything to pass through. If there is such a system setting in Windows 10 that would also apply to Samba shares, I'd like to know it.

But then, I'd have to apply that setting to every single machine. I think it would be better if it's possible to authenticate through VBA.
 

ysdai

Member
Local time
Today, 03:13
Joined
Nov 28, 2019
Messages
46
Actually, it doesn't really matter which OS hosts the share folder, what I'm really looking for is a way to authenticate and interact with network shares through code, the way you use connection objects, connection strings or drivers to authenticate and manipulate remote databases.

If all fails, then probably net use will be my only option to get past the authentication. And my next issue would be how to create a temporary network share that's usable by the code without mapping a drive. Create and destroy on the fly, so to speak.

Any ideas?
 

ysdai

Member
Local time
Today, 03:13
Joined
Nov 28, 2019
Messages
46
Figured it out myself. Turns out the solution is so simple that I was ashamed of myself for even asking.
Just put this line in the startup script or Form_Load event of the startup form, and this resource will stay accessible until the next reboot.
Code:
Shell "net use \\server\share /user:usr pwd", vbHide
It seems net use can indeed be used just to authenticate a network share, no drive mapping is necessary.
In my case, I can type anything in place of usr and pwd, but they must both be there or else there will be a command prompt window waiting for the user to type in the values. Of course you'll need to supply a valid username and password if the share actually requires it.
 
Solution

Users who are viewing this thread

Top Bottom