473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Accessing network PCs

Hi,

I'm looking to create a simple application that will copy files from a
folder on one PC on the network to another PC on the network but I am
having a bit of difficulty doing this. The problem is that the network
is not active directory and there is not a common username and
password between the PCs. The only way I can transfer files is if I
first open Windows Explorer and navigate manually to the PC enter the
username and password for access, this is not ideal as I would like
the application to be automated. Is there a way you can access another
PC and pass it a username and password or is there an alternative to
the approach I'm taking.

Any help would be much appreciated.

Thanks

Simon

May 23 '07 #1
4 2412
I'm looking to create a simple application that will copy files from a
folder on one PC on the network to another PC on the network but I am
having a bit of difficulty doing this. The problem is that the network
is not active directory and there is not a common username and
password between the PCs. The only way I can transfer files is if I
first open Windows Explorer and navigate manually to the PC enter the
username and password for access, this is not ideal as I would like
the application to be automated. Is there a way you can access another
PC and pass it a username and password or is there an alternative to
the approach I'm taking.

Any help would be much appreciated.

Thanks
This is a deep subject actually. My own expertise is from the WinAPI/C++
world so I'm not sure what .NET function to rely on off-hand but yes, you
can automate this with a different set of credentials than the logged on
(interactive) user. In fact it's the only practical/safe way to do it. Sorry
I don't know the .NET function to use without looking into it but I'd be
very surprised if there wasn't one (that wraps the WinAPI functions
""NetUseAdd()" or "WNetAddConnection2()" and cousins - you can always use
these of course even in .NET but I'm sure .NET provides its own analogue).
Note that you should also understand how authentication works in general and
how it's related to shared folders in particular (especially if this is for
a commercial app). You can get tripped up otherwise, even if things seem to
work at first. Your best bet is to get hold of "Programming Windows
Security" by Keith Brown though I'm not sure if it's in print anymore (it
goes back some years). It's still very relevant however and Chapter 8 in
particular is dedicated to your situation. I can also provide an intro on
this type of authentication in general if you want it. I wrote it some years
ago for a colleague and will post it on request (no API samples however
which I can't post for legal reasons).
May 23 '07 #2
"accyboy1981" <ac*********@gmail.comwrote in message
news:11**********************@u30g2000hsc.googlegr oups.com...
Hi,

I'm looking to create a simple application that will copy files from a
folder on one PC on the network to another PC on the network but I am
having a bit of difficulty doing this. The problem is that the network
is not active directory and there is not a common username and
password between the PCs. The only way I can transfer files is if I
first open Windows Explorer and navigate manually to the PC enter the
username and password for access, this is not ideal as I would like
the application to be automated. Is there a way you can access another
PC and pass it a username and password or is there an alternative to
the approach I'm taking.

Any help would be much appreciated.

Thanks

Simon

The easiest solution for this is to create a "use record" for your login
session.
the command should look like:
"net use \\otherpc\sharename passwd /user:validUserOnOtherpc"
The way you do this is by placing a "net use" command in your autoexec.bat
file.
Another option is to execute the above "net use" from your code (using
System.Diagnostics.Process.Start), this way you can delete the network
connection when done with it.
Note that you can use the IPC$ instead of a share name, this gives you
access to all of the resources on the "other" pc.
Willy.

May 23 '07 #3
The easiest solution for this is to create a "use record" for your login
session.
the command should look like:
"net use \\otherpc\sharename passwd /user:validUserOnOtherpc"
The way you do this is by placing a "net use" command in your autoexec.bat
file.
Another option is to execute the above "net use" from your code (using
System.Diagnostics.Process.Start), this way you can delete the network
connection when done with it.
Note that you can use the IPC$ instead of a share name, this gives you
access to all of the resources on the "other" pc.
There should be a .NET function for this somewhere however since spawning
"net.exe" from code is ugly IMO (and he shouldn't publish his password in a
batch file if he decides to go that route). Also note that IPC$ is really
just a login (authentication) resource for all intents and purposes (unlike
other resources where a DACL check is immediately conducted against the
resource). Once your're authenticated on the remote machine using IPC$, your
network session on that machine is still subject to normal access checks on
whatever resources you touch (which gets into shared resource permissions vs
normal NTFS permissions but that's another story). Access denied can still
occur IOW if you later touch a resource you don't have access to (whereas
access denied will occur right away if you authenticate against the target
resource from the outset, opposed to IPC$).
May 23 '07 #4
"Larry Smith" <no_spam@_nospam.comwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
>The easiest solution for this is to create a "use record" for your login
session.
the command should look like:
"net use \\otherpc\sharename passwd /user:validUserOnOtherpc"
The way you do this is by placing a "net use" command in your
autoexec.bat file.
Another option is to execute the above "net use" from your code (using
System.Diagnostics.Process.Start), this way you can delete the network
connection when done with it.
Note that you can use the IPC$ instead of a share name, this gives you
access to all of the resources on the "other" pc.

There should be a .NET function for this somewhere however since spawning
"net.exe" from code is ugly IMO (and he shouldn't publish his password in
a batch file if he decides to go that route). Also note that IPC$ is
really just a login (authentication) resource for all intents and purposes
(unlike other resources where a DACL check is immediately conducted
against the resource). Once your're authenticated on the remote machine
using IPC$, your network session on that machine is still subject to
normal access checks on whatever resources you touch (which gets into
shared resource permissions vs normal NTFS permissions but that's another
story). Access denied can still occur IOW if you later touch a resource
you don't have access to (whereas access denied will occur right away if
you authenticate against the target resource from the outset, opposed to
IPC$).

Unfortunaly there is no .NET API for this, and if there was, you would have
to pass the credentials anyway (as per WNetAddConnection2), Sure, I agree
you shouldn't hard code credentials, but all depends on the security
constraints imposed.
Now I suppose that the OP is talking about a home like environment, so
security is IMO not an issue, he knows the password (guess it's even the
administrators pwd) required to access the other PC's resources, which
implies a non-secured environmant anyway.
In such scenario, storing a pwd in a batch file he owns (say in his user
profile) doesn't impose such a security risk. If it is, or if he cares about
security, he should prompt for the credentials interactively and pass them
to the API he calls whatever this API may be. As to spawning "net use", is
IMO not that ugly, the Process.Start api provides everything to run the
command without showing the command windows, so why you consider this to be
ugly is beyond me, given the fact that there is no .NET API to connect to a
shared resource.
Willy.
May 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tony Baker | last post by:
Hi, being a Windows developer and not having anything to do with UNIX/Solaris, I have a few questions about accessing .Net Web Applications from such environments. If a client has a UNIX/Solaris...
1
by: Amy Tseng | last post by:
Hi, I am having a problem accessing SQL Server 2000 via UNIX. I am accessing SQL Server 2000 from Solaris using Sybase Open Client (CT-Lib). Here is the error message: CT-LIBRARY error:...
23
by: Lamberti Fabrizio | last post by:
Hi all, I've to access to a network file from an asp pages. I've red a lot of things on old posts and on Microsoft article but I can't still solve my problem. I've got two server inside the...
36
by: Thomas | last post by:
after spending countless hours trying, i give up and hope to get some help in here. on server1 i got the web myweb.com with my test.asp. in the test.asp, i'm trying to read a file from an UNC...
1
by: TJRobertsJob | last post by:
Was wondering if someone could help. Over the last month I've been developing a small database application, using Access 2000, for use in a friends shop. Everything was going well until about a...
5
by: Niloday | last post by:
Hi All, I am trying to access a mapped network drive from a service that I have created. The service needs to create/delete folders/files on a network drive. When I tried to connect to a...
1
by: Z0gS | last post by:
I got this problem for the web application I try to access files on a remote server. string dirs = Directory.GetDirectories(@"E:\vehicles") E drive is a map to a network drive. I get the...
1
by: mbah Sumani via .NET 247 | last post by:
(Type your message here) I Think it's the stupidness of Windows. Why the service can't access network drive but console apps or windows application can do it? So my suggestion is make the program...
19
by: cj | last post by:
I'm getting terrible response times trying to pull data from VFP tables using .net--like 2 minutes! Can someone help? f:\arcust01 currently contains 187,728 records and is indexed on CUSTNO...
2
by: dcblair | last post by:
Hi guys and girls. I can't seem to figure this one out. Here is my setup: Speedtouch 536 DSL Modem, Nexxt 4 Port Wireless Router, CNET CIC 920W Wireless IP Camera. The camera is set up in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.