Accessing a Windows share using username/password authentication

Accessing a Windows share using username/password authentication


I have recently had to solve this problem and would like to share my findings with you.


- You need your application to access a Windows share using UNC paths to read/write files.


- Mapping a network drive is not an option because that kind of access to the server machine is restricted.

- The location of the share is bound to change (frequently) and so the application must offer a management screen and allow these parameters to be changed in runtime.

- The access requires username/password authentication because the two machines don't share the same domain.

Possible solution:

Implement an extension that starts a process to execute the following:

net use <unc_path> /U:<user_name> <password>

e.g.: net use \\\ImportantFiles /U:myuser mypassword

After this you will have access to the <unc_path> and will be able to manipulate it according to the user permissions.

To "unmount" the share do something similar but now execute:

net use /DELETE <unc_path>

To spare you the trouble I have attached the Extension WindowsShare (requires Integration Studio or later to open).

It contains two actions, Connect and Disconnect. Both actions have two output parameters. One is the ErrorCode (0 is sucess) and the other is the ErrorMessage, which in case of error contains the Exception message or the stderr output of the "net use" process.

As to the input parameters, they are the same required by the "net use" command, i.e., (path, user, pass) for Connect and (path) for Disconnect.

I hope this will be of some use to you.

Paulo Miguel