?
Solved

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

Posted on 2014-09-15
8
Medium Priority
?
1,056 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 26

Expert Comment

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

Author Comment

by:countrymeister
ID: 40323514
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
ID: 40323607
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 1

Author Comment

by:countrymeister
ID: 40323707
I will try and do that, but do you have a solution to access a network share using a userid password.
0
 
LVL 26

Expert Comment

by:pony10us
ID: 40324165
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
ID: 40333358
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 1500 total points
ID: 40333471
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
ID: 40354705
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

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

741 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