Solved

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

Posted on 2004-04-12
10
309 Views
Last Modified: 2010-04-15
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
Comment
Question by:chennarh
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 4

Expert Comment

by:bkfirebird
ID: 10808556
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
 

Author Comment

by:chennarh
ID: 10808616
I tried that, it works good if I run the program from desktop. But when run it as a service, it fails.
0
 
LVL 9

Expert Comment

by:Cayce
ID: 10809112
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 10809840
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
 
LVL 1

Expert Comment

by:ico2
ID: 10816585
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
 
LVL 1

Expert Comment

by:ico2
ID: 10816604
note the password is the administrator pword from the other machine.
0
 
LVL 86

Expert Comment

by:jkr
ID: 10816608
>>system("net use x: \\\\othermachine\\sharename\\ password");

Why pop open a dos box if there is an API?
0
 

Author Comment

by:chennarh
ID: 10817478
Thanks jkr, that is the API i am looking for. I will try it tonight and post the result.
0
 

Author Comment

by:chennarh
ID: 10817487
Any idea of such APi in Java?
0
 
LVL 86

Expert Comment

by:jkr
ID: 10819272
Hum I don't know Java well, but I am sure that it is named the same there...
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In desperate need of help 8 137
Estimate porting issues. 9 119
Using unmanaged DLL from managed application 14 294
If a cell in a range equals "YES" return specific Test. 4 32
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

777 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