I have a windows forms app running on a machine that is not on a domain, that needs to be able to move a file from the local filesystem to a UNC path. I have a username and password for that path. I was wondering is there any way to do this directly with out execing the net.exe
command?
Ideally I wouldn't have to map a drive.
You can use WNetAddConnection to accomplish this. You will have to pInvoke. the code below worked for me after I set up the pInvoke declarations. The second block of code (below) contains the pInvoke declarations -- just stick it inside of a class.
You will need to paste the following supporting code into a class (taken from pInvoke.Net). Make sure to add a using statment to your code:
The accepted answer on this question here seems like it would be worth looking into; it suggests using the Win32 API function WNetUseConnection.
From MSDN:
Which seems to accomplish what you're looking for, with no mention of
net.exe
. Does this help?