Solved

How can I access a network share using userid / password in code

Posted on 2014-09-15
8
877 Views
Last Modified: 2014-10-01
I tried some open source that I found

  using (NetworkShareAccesser.Access("remoteComputername", "domain", "userid", "passoword"))
                        {
                            if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); }
                        }

But this gives me an error - network name not found
0
Comment
Question by:countrymeister
  • 4
  • 4
8 Comments
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
Did you also get the code for "NetworkShareAccesser"?
0
 
LVL 1

Author Comment

by:countrymeister
Comment Utility
Yes, of course, How else would my code compile and I would be able to debug and get that error
0
 
LVL 26

Expert Comment

by:pony10us
Comment Utility
I would verify you have all the correct variables set in the "NetworkShareAccesser" code.  The error you are getting indicates that it can't find the remote computer.
0
 
LVL 1

Author Comment

by:countrymeister
Comment Utility
I will try and do that, but do you have a solution to access a network share using a userid password.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 26

Expert Comment

by:pony10us
Comment Utility
I usually do it with Net Use:

net use \\server\share /user:name password

If you want to access the share afterwards:

start \\server\share

So you could save this as a batch file:

@echo off
net use \\server\share /user:name password
start \\server\share

Remember to use quotes around the name and/or password if they contain blanks.
0
 
LVL 1

Author Comment

by:countrymeister
Comment Utility
Pony itried Net use , but it does not work, because I have subdirectories and cannot get to the sub directories
0
 
LVL 26

Accepted Solution

by:
pony10us earned 500 total points
Comment Utility
Is this just a snippet of code for a larger project?  

Using what I provided would simply open the share in a window. This should allow you to access anything in the share.

If you are attempting to use this as a snippet of a larger piece of code to run unattended then you are correct that as written it will not work.

What you would need is to assign it a drive letter and access it using that letter.

For example:

net use z: \\server\share /user:name password
copy z:\subfolder\file.ext c:\folder
net use z: /delete

Open in new window


Would map the share to z: using the credentials provided, copy a file from the subfolder in the share to a folder on the C: drive and finally disconnect the Z: drive.

Is this closer to what you are wanting?
0
 
LVL 1

Author Closing Comment

by:countrymeister
Comment Utility
I had to change some of the Network Accessor code and got it to work. Cannot use net use in line project
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now