Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

how to pass username password to access a shared file on another computer

I have two Windows 2000 servers, one of them has a folder shared. From the second machine, I need to run a program as service that will read/write to the shared folder on the first machine. The passwords for the "administrator" user on both the machines are NOT same.

Thanks

Reddy
0
chennarh
Asked:
chennarh
  • 3
  • 3
  • 2
  • +2
1 Solution
 
bkfirebirdCommented:
map the shared folder to a drive letter and read/write as normal.
if you want to map the drive from code, look at www.experts-exchange.com/Programming/Programming_Languages/ Visual_Basic/Q_20860580.html
0
 
chennarhAuthor Commented:
I tried that, it works good if I run the program from desktop. But when run it as a service, it fails.
0
 
CayceCommented:
Why don't you use UNC paths?

You'll have to make both the shares available to whatever user the service runs as.

For instance.

\\MACHINE1\SHARE1 should allow Service1 account to Read/Write/Whatever

\\MACHINE1\SHARE2 should allow Service1account to Read/Write/Whatever

Both accounts should have the same password and the service shall be started with that username/password combo.

0
NEW Internet Security Report Now Available!

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out this quarters report on the threats that shook the industry in Q4 2017.

 
jkrCommented:
You need a session with valid credentials on that ther machine - use

NETRESOURCE nr;
ZeroMemory (&nr, sizeof (NETRESOURCE));
nr.dwType = RESOURCETYPE_DISK;
nr.lpLocalName = 0;
nr.lpRemoteName = "\\\\server\\path_on_server";

WNetAddConnection2(&nr, "password", "username", 0);

to establish one.
0
 
ico2Commented:
the easiest way is this:
system("net use x: \\\\othermachine\\sharename\\ password");
then read/write from x: to view files on the other machine.
0
 
ico2Commented:
note the password is the administrator pword from the other machine.
0
 
jkrCommented:
>>system("net use x: \\\\othermachine\\sharename\\ password");

Why pop open a dos box if there is an API?
0
 
chennarhAuthor Commented:
Thanks jkr, that is the API i am looking for. I will try it tonight and post the result.
0
 
chennarhAuthor Commented:
Any idea of such APi in Java?
0
 
jkrCommented:
Hum I don't know Java well, but I am sure that it is named the same there...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now